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 8781883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:25:26+00:00 2026-06-13T20:25:26+00:00

I am currently getting this output from my query:- Count(Total)| Type1 —————– 24 T1

  • 0

I am currently getting this output from my query:-

Count(Total)| Type1
-----------------
 24            T1

  22           T2

But I want the output like this:-

 T1   T2
----------
 24   22

Note that Type1 column can contain any values like T1,T2,T3 so I cannot fix the values in the query. I am using Oracle 10g, 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-06-13T20:25:28+00:00Added an answer on June 13, 2026 at 8:25 pm

    Oracle 10g does not have a PIVOT function so you can use an aggregate with a CASE:

    select 
      sum(case when type1 = 'T1' then total end) T1,
      sum(case when type1 = 'T2' then total end) T2
    from <yourquery goes here>
    

    See SQL Fiddle with Demo

    Or you can implement this directly into a query similar to this, using the SUM() aggregate will count each occurrence that matches the type1 value in the CASE statement:

    select 
      sum(case when type1 = 'T1' then 1 else 0 end) T1,
      sum(case when type1 = 'T2' then 1 else 0 end) T2
    from yourtable
    

    If you have an unknown number of values to transform into columns, then you will want to use a procedure similar to this:

    CREATE OR REPLACE procedure dynamic_pivot(p_cursor in out sys_refcursor)
    as
        sql_query varchar2(1000) := 'select ';
    
        begin
            for x in (select distinct type1 from yourtable order by 1)
            loop
                sql_query := sql_query ||
                  ' , sum(case when type1 = '''||x.type1||''' then 1 else 0 end) as '||x.type1;
    
                    dbms_output.put_line(sql_query);
            end loop;
    
            sql_query := sql_query || ' from yourtable';
    
            open p_cursor for sql_query;
        end;
    /
    

    Then to execute it:

    variable x refcursor
    exec dynamic_pivot(:x)
    print x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For this query: $sql='select col from table where other_col=?'; I am currently getting the
I'm doing a Firefox addon but I'm currently getting this error in the Error
I'm getting a result (the object) back from a mongoose query and want to
this is hard to describe but I am currently catching a string from a
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
I am currently getting first day Of this week and last week values with
I am currently working through this tutorial: Getting Started with jQuery For the two
I Believe I'm doing this correctly but it is not getting the stored cookie
This is code for get current date information is getting from database. It is
Basically, I'm getting a date time string from an API, and I want to

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.