Oracle 10g query rows to column transpose

In oracle 10g I have table called LoginUser
Select * from LoginUser where Day = '01-Dec-2012'
will give me the below result
Day, Name, Country
1-Dec-12 , John, UK
1-Dec12 , Cate, US
1-Dec-12 , Prakash, India
1-Dec-12 ,Juli, Pak
But I want result as below
Day, Name1, Country1, Name2, Country2, Name3, Country3, Name4, Country4
1-Dec-12, John, UK, Cate, US, Prakash, India, Juli, Pak
Please help
Edited by: 975340 on Dec 6, 2012 1:48 AM
Edited by: 975340 on Dec 6, 2012 1:50 AM

Refer to below thread
Re: Multiple rows into a single line in 'Single Column Table'

Similar Messages

  • Oracle 10g Query on Date Column

    Hello -
    What is the most efficient way to query on a date column to get all dates within the last 2 months? I use something like the following in the WHERE clause:
    billing_date >= to_date(add_months(sysdate, -2))
    However, I can't ever get the index on billing_date to be used.
    Any help is greatly appreciated...
    Thanks!!

    This is a perfectly valid way to query the data. Here's an example on my own production tables. This one has about 300 million rows:
    select *
    from   prod.tran_history
    where  tran_date >= to_date(add_months(sysdate, -2))
    | Id  | Operation                   |  Name                        | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT            |                              |    11M|   863M|   146K|
    |   1 |  TABLE ACCESS BY INDEX ROWID| TRAN_HISTORY                 |    11M|   863M|   146K|
    |*  2 |   INDEX RANGE SCAN          | TRAN_HIST_DATE_IDX           |  2144K|       |  2098 |
    --------------------------------------------------------------------------------------------

  • Rows to columns/Transpose the records Query and Display output

    hi ,
    can anyone help me query this and transpose it to this format?
    i am still a beginner in sql.
    thanks for help!
    Rows to columns/Transpose the records Query and Display output
    id     startdate     endate                    
    1111     1/2/2001     11/3/2001                    
    1111     2/5/2002     4/3/2002                    
    1111     2/6/2000     2/5/2001                    
    3333     5/2/2003     11/3/2003                    
    3333     6/2/2003     12/3/2003                    
    3333     2/6/2005     2/5/2005                    
    desired output     
    id     startdate1     endate1     startdate2     endate2     startdate3     endate3
    1111     1/2/2001     11/3/2001     2/5/2002     4/3/2002     2/6/2000     2/5/2001
    3333     5/2/2003     11/3/2003     6/2/2003     12/3/2003     2/6/2005     2/5/2005

    Have you only 3 dates for each id ?
    So, try :
    SQL> l
      1  with tbl as
      2  (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
      3  select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
      4  select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
      5  select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
      6  select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
      7  select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
      8  select id, max(decode(dr,1,startdate)) start1,
      9             max(decode(dr,1,enddate)) end1,
    10             max(decode(dr,2,startdate)) start2,
    11             max(decode(dr,2,enddate)) end2,
    12             max(decode(dr,3,startdate)) start3,
    13             max(decode(dr,3,enddate)) end3
    14  from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
    15* group by id
    SQL> /
                                                    ID START1   END1     START2   END2     START3   END3
                                                  1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
                                                  3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
    SQL> HTH,
    Nicolas.

  • Query rows to column

    dear Friends,
    i need query row to column
    example
    1 a data1 data2 data3
    2 b data1 data2 data3
    output format
    1 2 a
    data1 data2 data3

    Please consider the following when you post a question.
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there any option in oracle 10g to rename a column?

    Hi friends,
    Is there any option in oracle 10g to rename a column? Please send me reply....Waiting for that...

    You can even rename a column in oracle 8i or 9i
    E.g:
    ALTER TABLE TABLE_NAME RENAME COLUMN OLD_COLUMN_NAME TO NEW_COLUMN_NAME;Message was edited by:
    Mohana Kumari

  • Oracle 10G query

    I have following queries to be solved please help me out....
    1) Difference / Limitation of Oracle Standard Edition / Enterprise Edition 10..... latest ?
    2) Can Data of Oracle 8. ..... Expo File will be Imported to 10....... latest ?
    If not than what steps we have to take. Basically I would like my current DB of 8 to be moved to 10G
    3) From which AIX Ver Oracle 10 ...... is Supported ?
    4) if the customer has 8... Ver Lic When if goes for New Ver than media will have full Ver or only Upgrade files. ?
    5) If the Customer has Old ver Lic and he goes for upgrade Lic Than we have to first Install Old Lic Ver & than Upgrade or directly we can load Latest Lic Ver on New Server and work. ? What I mean is if I have to go ahead from Oracle 8 to Oracle 10G how should I go about.
    6) Is Oracle Media ver Compatible for Aix ?
    7) Oracle Lic Policy / Product Information Web Link ?
    Thanks & Regards
    Shivanand S S

    This is a perfectly valid way to query the data. Here's an example on my own production tables. This one has about 300 million rows:
    select *
    from   prod.tran_history
    where  tran_date >= to_date(add_months(sysdate, -2))
    | Id  | Operation                   |  Name                        | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT            |                              |    11M|   863M|   146K|
    |   1 |  TABLE ACCESS BY INDEX ROWID| TRAN_HISTORY                 |    11M|   863M|   146K|
    |*  2 |   INDEX RANGE SCAN          | TRAN_HIST_DATE_IDX           |  2144K|       |  2098 |
    --------------------------------------------------------------------------------------------

  • Oracle 10g Query Format

    0
    down vote
    favorite I am using oracle 10g. I have a temp table TEMP.
    TEMP has following structure:-
    USER COUNT TYPE
    1 10 T1
    2 21 T2
    3 45 T1
    1 7 T1
    I need a query which will show all types has column names,and types can be any value like T1,T2,..Tn and columns will be like:-
    USER T1 T2 Tn
    and User column will show all the users and T1,T2 column will show total count of types.
    Edited by: 969468 on Nov 15, 2012 9:35 PM

    Please see my original post ("I have a page erroring in production (but not in development) when it gets to a date that it needs to display.")  Sorry if it came across as vague.  It made sense, to me, when I typed it.  But, then, I'm usually typing fast just to get the question out there, when I'm in a hurry.
    Haven't done a CFDUMP, yet, as every time I make a change in development that needs to be tested in production, I have to notify my supervisor that there are files that need to be copied into production, which can sometimes take a while, so I try to do troubleshooting on dev side - it's a pain in the you-know-what, but that's the kind of environment I'm working in.
    As it turns out, changing the format in the SELECT to_char() did the trick.  If anyone else has this issue with Oracle 10g, I'm now using SELECT to_char(create_date,'YYYY/MM/DD HH:MI') FROM tableA, and now the CFOUTPUT is processing the whole page.  I guess the MM-DD-YYYY threw CF into a tizzy, breaking the process?
    Anyhoo, it's working, now.  Thank you, Dan and Adam, for your thoughts on this.
    ^_^

  • Dynamic query, row to column

    Hi.
    Is any way to select one row as column for any table exists?
    I mean some script which have table name and condition as input parameters, and prints column_name || column value;
    I have tried to do it, but have some problems.
    e.g. have table
    create table my_table (column1 number, column2 number, column3 number);
    insert into my_table values (1,2,3);It should be something like:
    declare
    lv_table_name varchar2(40):='MY_TABLE'; /*these are input paremeters*/
    lv_condition varchar2(300):='column1=1;/*these are input paremeters*/
    begin
    /*body*/
    end;and output should be like (may use dbms_output)
    column1    1
    column2    2
    column3    3    Script should work for any table.
    Does anybody solves task similar to this?

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
    Search for procedure print_table on that page.

  • SAP HANA View Row to Column Transpose

    Hello Guys
    What is the best way to transpose rows to columns within a Hana Model. I can find many articles that talk about Column to Row transpose.
    Source:
    Customer
    Dim 1
    Dim 2
    1000
    A
    1100
    1000
    B
    1200
    1000
    C
    1300
    Target:
    Customer
    A
    B
    C
    1000
    1100
    1200
    1300
    Thanks

    Not as an answer, but as a question: Are there three rows *only* resp. could they be granted? Or you wanna have the amount dynamic, i.e. count the same customers and than created the amount of required columns?

  • Transposing of queried rows into columns

    Hi, i have a query that produces an output of several rows (i.e. no. of days in a month).  How do I modify my query so that instead of getting 31 rows for january, I will have one row with 31 columns or values?  Thank you.

    Thank you very much for your response.  You definitely got what i wanted to do but honestly, I'm having a hard time applying this to my query since I am not very familiar with the WITH AS, CONNECT BY LEVEL and the PRIOR commands, coupled with the fact that I have to produce my output ASAP.  I have this query:
    SELECT A.PLTCODE, A.PLTACTLGEN, A.INPTDATE                    
        FROM PMC_ACTLGEN A                                       
       WHERE     A.INPTDATE >
                    TO_DATE ('10/31/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
             AND A.INPTDATE <
                    TO_DATE ('01/01/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS')
    ORDER BY                                                           --
            A.PLTCODE, A.INPTDATE
    which produce an output that looks like this:
    PLTCODE
    PLTACTLGEN
    INPTDATE
    AMB
    0
    11/1/2013
    AMB
    204
    11/2/2013
    AMB
    107
    11/3/2013
    AMB
    968
    11/4/2013
    AMB
    1379
    11/5/2013
    AMB
    1493
    11/6/2013
    AMB
    1457
    11/7/2013
    AMB
    1099
    11/8/2013
    AMB
    1893
    11/9/2013
    AMB
    2517
    11/10/2013
    AMB
    2521
    11/11/2013
    AMB
    2448
    11/12/2013
    AMB
    701
    11/13/2013
    AMB
    1785
    11/14/2013
    AMB
    2002
    11/15/2013
    AMB
    1601
    11/16/2013
    AMB
    1225
    11/17/2013
    AMB
    1572
    11/18/2013
    AMB
    1579
    11/19/2013
    AMB
    1576
    11/20/2013
    AMB
    1722
    11/21/2013
    AMB
    1610
    11/22/2013
    AMB
    175
    11/23/2013
    AMB
    813
    11/24/2013
    AMB
    1674
    11/25/2013
    AMB
    2198
    11/26/2013
    AMB
    1841
    11/27/2013
    AMB
    1970
    11/28/2013
    AMB
    1918
    11/29/2013
    AMB
    721
    11/30/2013
    How do I exactly modify this query to produce an output such that the INPTDATE is arranged as columns e.g.
    INPTDATE    1      2       3        4          5          6          7      .     .     .       30
    AMB            0     204   107     968     1379     1493    1457     .     .     .     721
    PLEASE HELP!  Thanks a lot!

  • Convert Oracle SQL query to single column output

    Hello All,
    I need to build the query to have multiple columns in a single column with multiple rows.
    select a.customer_trx_id,a.previous_customer_trx_id
    from ra_customer_trx_all a
    where a.customer_trx_id = :customer_trx_id
    here, a.customer_trx_id and a.previous_customer_trx_id are in two columns. I need to bring them into a single column.
    Say: the above output is
    a.customer_trx_id a.previous_customer_trx_id
    123456 87654
    Need to have single column
    As
    123456
    87654
    Please do the needful.
    Thanks,
    Abdul

    Hi,
    Post your question in [SQL and PL/SQL|http://forums.oracle.com/forums/forum.jspa?forumID=75] forum, you would probably get a better/faster response.
    Regards,
    Hussein

  • Oracle DB Query Generating Invalid Column Index error

    Dear All,
    Apologies for a question on this rather basic error but I don't understand why i'm experiencing the behaviour described.
    The piece of code below connects to a database, runs a query, then attempts to display the contents of the resultset. I understand from other posts on the topic that the query I am executing (INSERT INTO table VALUES (...)) as in the comments below needs to have autocommit disabled to allow me to access the resultset without the transaction closing.
      public void runQuery(String query) throws Exception {   Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con = DriverManager.getConnection(database, username, password); con.setAutoCommit(false); Statement st = con.createStatement();         ResultSet rs = st.executeQuery (query);         // "select * from user_tables"         // "INSERT INTO BH VALUES ('','2.25','Dark Red','Samsonite','4987638762')"         while (rs.next()) {         System.out.print (rs.getString(1)); // Exception thrown here     }         con.commit(); st.close();   con.close();   }
    I have removed try {} catch {} error handling for clarity.
    I am receiving the invalid column index error from the indicated line, which clearly suggest column 1 doesn't exist, however if i run the same query in another tool, something like the following is returned:
    Rows Affected
    1
    The query is being received by the database as the row ends up in the table intact, so I am clearly missing something about how to access the resultset correctly.
    I am guessing that I am either misusing/misunderstanding the autocommit option or that the resultset is different to what I am expecting...
    Can someone please shed a little light?
    Many thanks!
    George

    Ok, I've done a little more digging, and i've come to the conclusion that an INSERT query doesn't return a resultset (or returns an empty one)
    Could someone with a little more knowledge confirm this as I've had little luck finding an explicit yes or no from the web!
    Many Thanks in advance...

  • Oracle 10g - query is very slow in jdbc but not in other tools

    I'm using PreparedStatement to execute a query with some parameters.
    in sql developer, it just spends 12 seconds but in jdbc, it's around 140 seconds.
    I disabled "_optim_peek_user_binds" parameter already but it didn't help.
    alter session set "_optim_peek_user_binds"=false;

    Please mark this thread ANSWERED and repost it in the JDBC forum.
    https://forums.oracle.com/forums/category.jspa?categoryID=288
    When you post provide your 4 digit Oracle version, Java version and JDBC jar name and version as well as the code you are using.

  • Row and Column transpose question

    Dear Support ,
    I would like to transpose one internal table , for example :
    Column : MATERIAL , QTY , DATE
                  MA1          ,  100  , 2009-01-01
                  MA2          ,  200  , 2009-01-01
                  MA3          ,  200  , 2009-03-02
    After the convertion , it should be like that :
    Column : MATERIAL , 2009-01-01 , 2009-03-02
                  MA1            100                0
                  MA2             200               0
                  MA3             0                200
    As i know , in SQL it is very easy to do that , just like :
    select sum(case ' xxx ' when ' xxx ' .... ) ....
    But how to do that in ABAP ?
    Thanks .
    Carlos Zhang

    Hi,
    Please find teh code as follows
    TYPES : BEGIN OF t_itab,
             mat TYPE matnr,
             qty TYPE menge_d,
             dat TYPE datum,
            END OF t_itab.
    TYPES : BEGIN OF t_datcol,
             dat TYPE datum,
             col TYPE i,
            END OF t_datcol.
    DATA : tbl_obj  TYPE REF TO data,
           line_obj TYPE REF TO data.
    DATA : lv_field TYPE fieldname.
    DATA : wa     TYPE t_itab,
           wa_col TYPE t_datcol.
    DATA: itab    TYPE STANDARD TABLE OF t_itab,
          itab_dt TYPE STANDARD TABLE OF t_datcol.
    DATA : fcat TYPE lvc_t_fcat.
    DATA : fcat_wa TYPE lvc_s_fcat.
    DATA: cntr TYPE i.
    FIELD-SYMBOLS : <fs>          TYPE t_datcol,
                    <fs_mainitab> TYPE STANDARD TABLE,
                    <fs_line>     TYPE ANY,
                    <fs_field>    TYPE ANY.
    wa-mat = 'M1'.
    wa-qty = 100.
    wa-dat = '20090101'.
    APPEND wa TO itab.
    wa_col-dat =  '20090101'.
    APPEND wa_col TO itab_dt.
    wa-mat = 'M2'.
    wa-qty = 200.
    wa-dat = '20090101'.
    APPEND wa TO itab.
    wa_col-dat =  '20090101'.
    APPEND wa_col TO itab_dt.
    wa-mat = 'M3'.
    wa-qty = 200.
    wa-dat = '20090302'.
    APPEND wa TO itab.
    wa_col-dat =  '20090302'.
    APPEND wa_col TO itab_dt.
    SORT itab_dt BY dat.
    DELETE ADJACENT DUPLICATES FROM itab_dt COMPARING dat.
    fcat_wa-fieldname = 'MAT'.
    fcat_wa-ref_field = 'MATNR'.
    fcat_wa-ref_table = 'MARA'.
    APPEND fcat_wa TO fcat.
    LOOP AT itab_dt assigning <fs>.
      <fs>-col = sy-tabix.
      CONCATENATE 'F_' <fs>-dat INTO lv_field.
      fcat_wa-fieldname = lv_field.
      fcat_wa-ref_field = 'MENGE'.
      fcat_wa-ref_table = 'MSEG'.
      APPEND fcat_wa TO fcat.
    ENDLOOP.
    now make your main internal table as required
    dynamic table only incase if you do not know the dates
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog           = fcat
      IMPORTING
        ep_table                  = tbl_obj
      EXCEPTIONS
        generate_subpool_dir_full = 1
        OTHERS                    = 2.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ASSIGN tbl_obj->* TO <fs_mainitab>.
    CREATE DATA line_obj LIKE LINE OF <fs_mainitab>.
    ASSIGN line_obj->* TO  <fs_line> .
    IF <fs_mainitab> IS ASSIGNED AND <fs_line> IS ASSIGNED.
      LOOP AT  itab INTO wa.
        ASSIGN COMPONENT 'MAT' OF STRUCTURE <fs_line> TO <fs_field>.
        IF <fs_field> IS ASSIGNED.
          <fs_field> = wa-mat.
          UNASSIGN <fs_field> .
          READ TABLE itab_dt INTO wa_col
          WITH KEY dat = wa-dat.
          IF sy-subrc EQ 0.
            cntr = wa_col-col + 1.
            ASSIGN COMPONENT cntr OF STRUCTURE <fs_line> TO <fs_field>.
            IF <fs_field> IS ASSIGNED.
              <fs_field> = wa-qty.
              COLLECT <fs_line> INTO <fs_mainitab>.
              UNASSIGN <fs_field> .
            ENDIF.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDIF.
    Regards,
    Ankur Parab
    Edited by: Ankur Parab on Jun 24, 2009 4:04 PM

  • Selective export failing - Solaris Sparc - Oracle 10g

    HI Gurus,
    I am trying to export selective data from one of my prod database tables. But not succeeding. I was keep on trying for the past 2 hours.
    Could anybody please verify the script and let me know what was wrong in it. Thanks in advance
    OS : SOLARIS SPARC
    ORACLE - 10G
    Query --> WHERE E3RECV_DT LIKE '201305%' (I need to export this query data)
    Below Script i am using
    ===============
    exp E3USER@SGEBAPU2 statistics=none consistent=n buffer=100000000 file=exp_pipe_file TABLES=IFDATA query=\"WHERE E3RECV_DT LIKE '201305\%'\" log=PGTB_IFDATA_conditional.log

    Nagaraju P wrote:
    HI Gurus,
    I am trying to export selective data from one of my prod database tables. But not succeeding. I was keep on trying for the past 2 hours.
    Could anybody please verify the script and let me know what was wrong in it. Thanks in advance
    OS : SOLARIS SPARC
    ORACLE - 10G
    Query --> WHERE E3RECV_DT LIKE '201305%' (I need to export this query data)
    Below Script i am using
    ===============
    exp E3USER@SGEBAPU2 statistics=none consistent=n buffer=100000000 file=exp_pipe_file TABLES=IFDATA query=\"WHERE E3RECV_DT LIKE '201305\%'\" log=PGTB_IFDATA_conditional.logconsider placing everything on Control file to avoid fighting with the command line interpreter.
    my car is not succeeding.
    Tell me how to make my car go.
    use COPY & PASTE so we can see what you do & exactly how Oracle responds.
    How do I ask a question on the forums?
    SQL and PL/SQL FAQ

Maybe you are looking for