Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:48:20+00:00 2026-06-10T16:48:20+00:00

I am normally working with MS SQL. I have a piece of code which

  • 0

I am normally working with MS SQL. I have a piece of code which I might have to translate to Oracle SQL. In this piece of code I update two variables for each row in order to find the max value of concurrent users.

My question is if it is possible to do the same as what is being done in the MS SQL code below in Oracle?

-- The creation of this test table is not relevant to my question.
-- It is just there to make a working example
SELECT {ts '2012-09-03 10:12:00'} AS eventTime, 1 AS change
INTO #EVENTS
UNION ALL SELECT {ts '2012-09-03 10:24:00'}, 1
UNION ALL SELECT {ts '2012-09-03 10:25:00'}, 1
UNION ALL SELECT {ts '2012-09-03 11:02:00'}, -1
UNION ALL SELECT {ts '2012-09-03 11:25:00'}, 1
UNION ALL SELECT {ts '2012-09-03 11:34:00'}, 1
UNION ALL SELECT {ts '2012-09-03 12:15:00'}, -1
UNION ALL SELECT {ts '2012-09-03 13:50:00'}, -1
UNION ALL SELECT {ts '2012-09-03 14:20:00'}, -1
UNION ALL SELECT {ts '2012-09-03 14:44:00'}, -1

DECLARE @count int, @maxUsers int
SET @count = 0
SET @maxUsers = 0

-- This part is what is in question. Can you do something similar in Oracle?
-- Having calculation done for each row and store it in a variable for
-- the next row.
SELECT
    @count = @count + change,
    @maxUsers = CASE WHEN @count > @maxUsers THEN @count ELSE @maxUsers END
FROM #EVENTS
ORDER BY eventTime ASC

PRINT @maxUsers -- Prints the value 4

DROP TABLE #EVENTS
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:48:22+00:00Added an answer on June 10, 2026 at 4:48 pm

    Oracle has analytic functions that can be used to get things like running totals.

    SELECT MAX(CURRENTUSERS) FROM
    (
      SELECT SUM(CHANGE) OVER (ORDER BY eventTime) AS CURRENTUSERS 
      FROM EVENTS
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed Eclipse Indigo and the auto-complete feature is working normally in the
I normally wouldn't do this, but the project I'm currently working on requires a
I'm working on ogre project by using C++. Normally I use viewport:setbackground() but this
I have a problem with updating the value of property from code which is
On launch, my marquee text is working normally. Then i want to update text
I have an app, has a service.. its working normally when screen is on....
I've been working normally in Debug scheme, now I changed to Release and Im
Yesterday the application was working normally, and i didn't edit my codes. But now
OK, so my websites been working normally up until now, I'm not really sure
I just started using virtualenv, and it was working normally until yesterday. Now, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.