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

  • Home
  • SEARCH
  • 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 7592083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:49:01+00:00 2026-05-30T20:49:01+00:00

I am using oracle 11g and have written a stored procedure which stores values

  • 0

I am using oracle 11g and have written a stored procedure which stores values in temporary table as follows:

 id    count   hour   age   range
-------------------------------------
0       5       10     61     10-200
1       6       20     61     10-200
2       7       15     61     10-200  
5       9       5      61     201-300
7       10      25     61     201-300
0       5       10     62     10-20
1       6       20     62     10-20
2       7       15     62     10-20  
5       9       5      62     21-30
1       8       6      62     21-30
7       10      25     62     21-30
10      15      30     62     31-40

now using this temp table i want to return two cursors. one for 61 and one for 62(age).
and for cursors there distinct range will be columns . for example cursor for age 62 should return following as dataset.

user      10-20       21-30       31-40
         Count/hour  count/hour  count/hour
----------------------------------------------
0         5     10      -   -      -    -     
1         6     20      8   6      -    -    
2         7     15      -   -      -    -       
5         -      -      9   5      -    -         
7         -      -      10  25     -    -       
10        -      -      -   -      15   30          

this column range in temp table is is not a fixed values these are referenced from other table.

edited: i am using PIVOT for above problem, all examples i saw in internet are there for fixed values of column values (range in my case). how can i get dynamic values. following is the ex query:

SELECT *
FROM   (SELECT column_2, column_1
    FROM   test_table)
PIVOT  (SUM(column1) AS sum_values FOR (column_2) IN ('value1' AS a, 'value2' AS b, 'value3' AS c));

Instead of using handwritten value i am using following query inside ‘IN’

SELECT * from(
with x as (
  SELECT DISTINCT range 
          FROM test_table
         WHERE age = 62 )
select ltrim( max( sys_connect_by_path(range, ','))
                keep (dense_rank last order by curr),
              ',') range
  from (select range,
               row_number() over (order by range) as curr,
               row_number() over (order by range) -1 as prev
          from x)
connect by prev = PRIOR curr
  start with curr = 1 )

it is giving error in this case. But when i using handwritten values its giving right output.

select * from (select user_id, nvl(count,0) count, nvl(hour,0) hour,nvl(range,0) range,nvl(age,0) 
age from test_table)
  PIVOT (SUM(count) as sum_count, sum(hour) as sum_hour for (range) IN 
(

'10-20','21-30','31-40' 
 )
) where age = 62 order by userid

how can i give values dynamically there?
how can i do it.

  • 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-05-30T20:49:02+00:00Added an answer on May 30, 2026 at 8:49 pm

    Cursors are slow, I would recommend trying to do this in a query unless there’s no alternative (or speed doesn’t matter). You may want to look into: PIVOT / UNPIVOT which can rotate columns (in this case “range”).

    Here’s some PIVOT / UNPIVOT documentation and examples:
    http://www.oracle-developer.net/display.php?id=506

    Based on your last edit:

    Pretty sure you have two options:

    1. Build dynamic sql based on the distinct values found in the “range” column.

      You’ll probably be stuck using a cursor again to build the column names but at least it will be limited to just the distinct ranges.

    2. Oracle has a PIVOT XML command that you can use for this.

      See: http://www.oracle.com/technetwork/articles/sql/11g-pivot-097235.html

      And scroll down to the section: “XML Type”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Oracle 11g, and I have a lot of stored procedure code
we have written a C# 3.5 client talking to an Oracle database (11g) using
I am using oracle 11g and have a table with an XMLType. There are
I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table
I'm using Oracle 11g R2. I have a table with 9.1 billion rows. When
I'm trying to make a Java Stored Procedure in Oracle 11g which retrieve Google
Using .Net and Oracle 11g - I've been returning dataTables from a procedure inside
Using Oracle 11g release 2, the following query gives an ORA-01790: expression must have
I am connecting C# with Oracle 11g. I have a DataTable which i fill
We have an Oracle 11g database table with around 35 million rows. We are

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.