How to convert (multiple) rows output to multiple (columns)

Hii
I have wierd query. But not sure of how to get result out of it!!!
My query returns two rows for a query that i have posed.
Current Result
10
20
Expected Result
10 20
My problem here is i wanted the above two values to be stored in two variables in a single select statement.
If i use a cursor my problem will be solved.But i am not much intrested to use a cursor for a simple select statement.
is there any possibilty that i can convert the output of two rows to two columns??
I am using Oracle Release 10.1.0.2.0
Operating system Windows Xp.
People here will not appreciate the tags "Urgent". I know that :-(.
But some how i am forced to use this tag "urgent". Sorry for that.
If no answers i will in other way have to go to cursor :-(
Any help will be appreciated.
Thanks,
Pavan

Another solution with model and you don't need a subquery
SELECT  DEPT ,SUBSTR(LOCATION1,2) LOCATION1, SUBSTR(LOCATION2,2) LOCATION2,SUBSTR(LOCATION3,2) LOCATION3
    FROM   T
    MODEL
      RETURN UPDATED ROWS 
     PARTITION BY ( DEPT )
      DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY DEPT ORDER BY LOCATION ) AS POSITION )
      MEASURES     ( location,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION1 ,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION2,
                               CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION3 )IGNORE NAV
     RULES
       UPSERT
       ITERATE( 1000)
         UNTIL ( PRESENTV(LOCATION[ITERATION_NUMBER+2],1,0) = 0)
       ( LOCATION1[0] =LOCATION1[0] || CASE WHEN ITERATION_NUMBER+1=1 THEN  ',' || LOCATION1[ ITERATION_NUMBER+1] END,
         LOCATION2[0] =LOCATION2[0] || CASE WHEN ITERATION_NUMBER+1=2 THEN  ',' || LOCATION2[ ITERATION_NUMBER+1] END,
          LOCATION3[0] =LOCATION3[0] || CASE WHEN ITERATION_NUMBER+1=3 THEN  ',' || LOCATION3[ ITERATION_NUMBER+1] END  )
   ORDER BY DEPT
Demo
SQL> WITH T AS (   SELECT 'AB' DEPT,'MEB' LOCATION FROM DUAL UNION ALL
  2                SELECT 'AB','MEB1' FROM DUAL UNION ALL
  3                SELECT 'AB','MEB2' FROM DUAL UNION ALL
  4                SELECT 'BC','MEB' FROM DUAL UNION ALL
  5                SELECT 'BC','MEB' FROM DUAL UNION ALL
  6                SELECT 'CD','MEN' FROM DUAL UNION ALL
  7                SELECT 'CD','MEN' FROM DUAL
  8                )
  9  SELECT  DEPT ,SUBSTR(LOCATION1,2) LOCATION1, SUBSTR(LOCATION2,2) LOCATION2,SUBSTR(LOCATION3,2)
LOCATION3
10      FROM   T
11      MODEL
12        RETURN UPDATED ROWS 
13       PARTITION BY ( DEPT )
14        DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY DEPT ORDER BY LOCATION ) AS POSITION )
15        MEASURES     ( location,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION1 ,CAST ( LOCATION AS
VARCHAR2(15)) AS LOCATION2,
16             CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION3 )IGNORE NAV
17       RULES
18         UPSERT
19         ITERATE( 1000)
20           UNTIL ( PRESENTV(LOCATION[ITERATION_NUMBER+2],1,0) = 0)
21         ( LOCATION1[0] =LOCATION1[0] || CASE WHEN ITERATION_NUMBER+1=1 THEN  ',' || LOCATION1[ I
TERATION_NUMBER+1] END,
22        LOCATION2[0] =LOCATION2[0] || CASE WHEN ITERATION_NUMBER+1=2 THEN  ',' || LOCATION2[ ITER
ATION_NUMBER+1] END,
23        LOCATION3[0] =LOCATION3[0] || CASE WHEN ITERATION_NUMBER+1=3 THEN  ',' || LOCATION3[ ITER
ATION_NUMBER+1] END  )
24     ORDER BY DEPT
25     /
DE LOCATION1      LOCATION2      LOCATION3
AB MEB            MEB1           MEB2
BC MEB            MEB
CD MEN            MEN
SQL>
SQL> 

Similar Messages

  • How to convert the row in to a column.

    Hi All,
    i am having a query like this.
    select
    COUNT(PA_COL1),
    COUNT(PA_COL2)
    from ref_item;
    here PA_COL1,PA_COL2 are column of table ref_item.
    the out of this query is some thing like this
    PA_COL1 PA_COL2
    20000 12376
    i want the output to be like
    column record_count
    PA_COL1 200000
    PA_COL2 12376
    Please help me to get the query for this.
    also you have 30 columns in the table ref_item from PA_COL1 ....... PA_COL30.

    Just cutting it out, I mistakenly pasted the wrong example here...thanks for pointing it out...
    I am pasting a pretty good example from that thread itself, obviously you need to modify it to fit your need and thats the only way to learn:
    WITH t AS
    --( SELECT 'A' col FROM dual--
    UNION ALL
    SELECT 'B' FROM dual
    UNION ALL
    SELECT 'C' FROM dual
    UNION ALL
    SELECT 'D' FROM dual
    SELECT REPLACE(MAX(SYS_CONNECT_BY_PATH(col,' ')),' ') "Col"
    FROM
    --(SELECT col,--
    row_number() over (Order By col)    AS curr,
    row_number() over (Order By col) -1 AS prev
    FROM t
    CONNECT BY prev = Prior curr
    START WITH curr = 1;
    Edited by: Ankit Rathi on May 15, 2012 1:26 AM

  • How to insert multiple column in JExcel

    Hello,
    I'm having a problem with JXL, when I want to insert multiple columns by the below loop, but it doesn't work. It just insert two columns instead of 7 columns.
    while (date.before(toDate)) {
         sheet.insertColumn(1);
         Label l = new Label(1,row++, "Day");
         sheet.addCell(l);
         sheet.addCell(new DateTime(1, row, date.getTime(), dateFormat));
    Anyone know how to insert multiple columns in JXL?
    Thanks!

    Check the while condition. May be it is iterating only two times

  • Converting multiple columns into one.

    All,
    I have a requirement to convert multiple columns into one. Following is the pseudo code of current implementation. It unions the various columns ( col1, col2........) into a new column new_col. But perforamnce is extrmely slow owing to multiple unions. It may be noted that tables and where conditions of all these queries are same.
    Can you help me create a more efficient query?
    select col1 , col2, col3, col4 from my_tables where some_cols = my_condition;Below is the query used to convert these columns into one.
    select col1 new_col from my_tables where some_cols = my_condition
    union all
    select col2 from my_tables where some_cols = my_condition
    union all
    select col3 from my_tables where some_cols = my_condition
    union all
    select col4 from my_tables where some_cols = my_condition

    Without looking at those things you could be barking up the wrong tree by assuming the issue relates to the unioning of queries or other such things.Well, might be.........
    Execution time of this query (just the execution time not the retrival) is around 34 seconds with connect-by clause for returning 22,000 records.
    Here's the plan
    Execution Plan
    | Id  | Operation                          | Name                        | Rows
    | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                             |   326
    | 33904 |   135   (2)|
    |   1 |  SORT ORDER BY                     |                             |   326
    | 33904 |   135   (2)|
    |   2 |   MAT_VIEW ACCESS BY INDEX ROWID   | MV_COMQ_RM_DEAL             |     1
    |    62 |     1   (0)|
    |   3 |    NESTED LOOPS                    |                             |   326
    | 33904 |   134   (1)|
    |   4 |     MERGE JOIN CARTESIAN           |                             |   326
    | 13692 |     3   (0)|
    |   5 |      VIEW                          |                             |     1
    |    13 |     2   (0)|
    |   6 |       COUNT                        |                             |
    |       |            |
    |   7 |        CONNECT BY WITHOUT FILTERING|                             |
    |       |            |
    |   8 |         FAST DUAL                  |                             |     1
    |       |     2   (0)|
    |   9 |      BUFFER SORT                   |                             |   326
    |  9454 |     3   (0)|
    |  10 |       TABLE ACCESS BY INDEX ROWID  | SF_SEARCH_IDS_TMP_COMQ      |   326
    |  9454 |     1   (0)|
    |  11 |        INDEX RANGE SCAN            | IDX1_SF_SEARCH_IDS_TMP_COMQ |   349
    |       |     1   (0)|
    |  12 |     INDEX RANGE SCAN               | IDX_MV_COMQ_RM_DEAL         |     9
    |       |     1   (0)|
    -----------------------     Hope, It's readable.......
    I would have posted sample data and query but........I cant do that...:(

  • How to make Multiple column listbox in CS4 using tree view

    Hi ,
    I am a beginer in Indesign Cs4 plug-in creation.In one scenario i want to create multiple column listbox,i tried with one cloumn using tree view and that is working fine.so suggest how to create multiple column listbox using tree view.
    thanks
    Arun

    InDesign does not have a native multi-column widget. You have three options:
    1) Use the treeview widget and align your widgets in the tree node to create the illusion of columns (stroke panel is an example - the Links panel in CS4 is a better example)
    2) Go the way of the CellPanel SDK example and tweek it to work like a listbox
    3) Create the User Interface in Flex

  • How to add multiple columns?

    Using designer API, how to add multiple columns to the repository tables? I want to add number of columns at a time instead of adding column by column.
    Thanks in advance.

    Can you use sqlplus?
    ALTER TABLE table_name ADD (column_name data_type), (Column_name datatype),...
    Check the SQL Reference 11-9.
    Hope this helps.
    Bill Swanson

  • How to retrieve multiple columns using "returning" in the Insert query.

    hi,
    wanted to know how to retrieve multiple columns using "returning" in the Insert Query.
    For retrieving one column we write the query as follows:
    Insert into TABLE values(1,2,3,4) returning COLUMN1 into PARAMETER
    But can we retrive multiple columns in the same query?
    am using oracle 10g and coding in .NET

    Hi,
    You can definetely get multiple values from a single query using the 'returning' clause.
    Eg : insert into emp (empno, ename, job, deptno) values (7324,'ADAM','MARKETING',30) returning ename, deptno into var1, var2; PN : var1 & var2 to be declared as varchar2 & number respectively.
    More insight into the 'RETURNING' clause in this link.
    http://www.samoratech.com/PLSQL/swArtPLSQLReturn.htm
    Regards,
    Bhanu.

  • How to convert Oracle Report Output to Excel Spread Sheet..

    Hello Sir,
    How to convert Oracle Report Output to Excel Spread Sheet..
    Thanks..

    Hello,
    Please give us more information what kind of report(s). Sample example etc.,
    Sri

  • How to convert a row into a column with the row headers displayed as column in javaFx?

    How do in convert a row of data into column of data to display as shown below:
    Column1|Column2|Column3|Column4
    C1          | C2          | C3           |  C4
    C5          | C6          | C7           |  C8
    How to convert the above default behavior to as below
    Column1| C1 | C5
    Column2| C2 | C6
    Column3| C3 | C7
    Column4| C4 | C8

    .

  • Converting multiple column in single column

    Hi All,
    I need to create a table with single column by using select statement with multiple columns
    For Ex- i have 1 row with 10 columns (may be more than 10) like
    'A','B','C','D','E','F','G','H',I','J'
    i written sql like
    select 'A','B','C','D','E','F','G','H','I','J' from dual
    result is - 'A','B','C','D','E','F','G','H','I','J' with 10 columns
    Now i need output lik this using SQL
    Text
    'A'
    'B'
    'C'
    'D'
    'E'
    'F'
    'G'
    'H'
    'I'
    'J'
    Please help me to sort out this problem. Your help would highly appropriated.
    Regards
    Raju
    Edited by: 888667 on Apr 8, 2013 10:54 PM
    Edited by: 888667 on Apr 8, 2013 10:56 PM

    Welcome to the forum!!! You can convert column to row like this
    SQL>with my_table
      2  as
      3  (
      4  select 'A' col1,'B' col2,'C' col3,'D' col4,'E' col5,'F' col6,'G' col7,'H' col8,'I' col9,'J' col10
      5    from dual
      6  )
      7  select decode(no , 1, col1, 2, col2, 3, col3, 4, col4, 5, col5, 6, col6, 7, col7, 8, col8, 9, col9, 10, col10) col
      8    from my_table
      9    cross join (select level no from dual connect by level <= 10)
    10  /
    C
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    10 rows selected.
    SQL> To ask question in a better way please read {message:id=9360002} from FAQ

  • ALV: How to sort multiple columns?

    Hi all,
    Good morning!
    I have a requirement to sort multiple columns in ALV. I did a search and tried with following codes:
    data: lo_config_alv  type ref to cl_salv_wd_config_table.
    lo_config_alv->if_salv_wd_table_settings~set_multi_column_sort( value = abap_true ).
    But I still can not sort for multiple columns.
    Please guide me how to do that.
    Thanks,
    Khanh

    Hello,
    If you want to sort ALV by multiple fields, then you have to create sort rule for each field and set sort position for each field to specify the sequence in which you want to sort multiple columns.
    Here is a sample code:
    * Sort rows by PRICE descending
      DATA: lr_field1 TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule1 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field1 = lv_value->if_salv_wd_field_settings~get_field( 'PRICE' ).
      lr_field1->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
                                                   RECEIVING value = lr_rule1 ).
      lr_rule1->set_sort_position(  2 ). "set the sort position to 2
    * Sort rows by seatsmax descending
      DATA: lr_field2 TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule2 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field2 = lv_value->if_salv_wd_field_settings~get_field( 'SEATSMAX' ).
      lr_field2->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
                                                              RECEIVING value = lr_rule2 ).
      lr_rule2->set_sort_position( 1 ). "set the sort position to 1
    * Sort rows by seatsocc descending
      DATA: lr_field TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule3 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field = lv_value->if_salv_wd_field_settings~get_field( 'SEATSOCC' ).
      lr_field->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
      RECEIVING value = lr_rule3 ).
      lr_rule3->set_sort_position( 3 ). "set the sort position to 3
    In the above code, the sequence of sorting would be seatsmax price seatsocc
    If you dont specify the sort position, then the sequence of sorting would be the order in which the sort rules are created.
    In the above example, if we didnt set sort positions for the fields, then order would be price seatsmax seatsocc.
    Refer to this link for more info: https://cw.sdn.sap.com/cw/docs/DOC-33859
    Hope this helps!
    Regards,
    Srilatha

  • How to convert Report Builder output to .XLS

    Dear All,
    Let me please know how to convert the Report Builder output to Excel Format.
    As there are having the facility to convert the output in .PDF or .HTML format but i want to convert that into Excel Sheet......
    Please Guide me in this regards
    Thanks in advance
    Regards,
    Vishal......

    What version of reports are you running?
    If it's Reports 10g then have you looked at the help under the topic "About spreadsheet output"?

  • How to force multiple columns in the Details section

    Hello,
    My report has a lot of data in the Details section, but it could fit on one page if I could put it in three columns. Is there a way to do this?
    The Details section has setting: Force the new page after certain number of visible records. This would be perfect for me if instead of multiple pages I could use multiple columns.
    Thank you,
    Peter

    Thank you.
    I think I see now how to format the columns.
    Peter
    Edited by: Peter Afonin on Sep 10, 2010 2:34 PM

  • How to pivot multiple columns

    Hi,
    I am a newbie in t-sql and i am stuck with pivoting multiple columns. Any help is greatly appreciated!.
    My input table:
    Storeid
    ProductID
    Location
    Sat qty
    sun qty
    Mon qty
    Sat Sales
    Sun Sales
    Mon Sales
    123
    1
    IL
    5
    6
    2
    120
    88
    200
    333
    1
    GA
    2
    3
    8
    200
    120
    80
    456
    2
    CA
    4
    7
    3
    50.5
    93
    300
    I want to achieve output as below:
    Day
    StoreID
    ProductID
    Location
    Qty
    Sale
    Saturday
    123
    1
    IL
    5
    120
    Saturday
    333
    1
    GA
    2
    200
    Saturday
    456
    2
    CA
    4
    50.5
    Sunday
    123
    1
    IL
    6
    88
    Sunday
    333
    1
    GA
    3
    120
    Sunday
    456
    2
    CA
    7
    93
    Monday
    123
    1
    IL
    2
    200
    Monday
    333
    1
    GA
    8
    80
    Monday
    456
    2
    CA
    3
    300
    Please help me in writing t-sql query to get above output. Thank you !

    this?
    SELECT 1 AS dayNo,'Saturday' AS DayName,Storeid,ProductID,Location,Satqty AS Qty,SatSales AS Sales
    FROM table
    UNION ALL
    SELECT 2,'Sunday' AS DayName,Storeid,ProductID,Location,Sunqty AS Qty,SunSales AS Sales
    FROM table
    UNION ALL
    SELECT 3,'Monday' AS DayName,Storeid,ProductID,Location,Monqty AS Qty,MonSales AS Sales
    FROM table
    ORDER BY DayNo,Storeid
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to hide multiple columns in multicolumn listbox like as an excel sheet?

    Hello All,
    I have large amount of data that is to be displayed on multicolumn listbox. After displaying that, I want to hide or delete some columns from listbox in runtime.
    I know how to hide one column using active cell property node. But I want to hide multiple columns. I am using LabVIEW 2011. 
    Thanks in advance.
    Thanks & Regards,
    Manisha

    Thank you so much. 
    But I have total 12 columns and I don't want to delete columns serially. I want to delete inbetween columns, like in attached VI I want to delete column A & D only. 
    And in this user have to select it from frontpanel. I want this is to be done as in excel, like we select the entire column and either we hide it or delete it. One more thing I want to clear the data in multicolumn when I next time open my VI. How to do that?
    I hope am clear in explaining my problem.
    Thanks & Regards,
    Manisha
    Attachments:
    Delete Column.vi ‏10 KB

  • How to Sort Multiple Column In ALV_LIST_DISPLAY

    Dear Experts,
                         Recently i've facing a problem to Sort multiple Column in ALV_LIST_DISPLAY.Whenever i need to sort 4 columns at a time , only 3 was sorted not the 4'th one.But i have already clearly mentioned in my sort section .Can anybody help me overcome this problem?
    warm regards,
    sameek mazumder.

    Hi samgpi,
    You should have no prolem with doing such sorting by using the parameter IT_SORT, available when using class or FM...
    Can you paste you sort section here so we can have a closer look?
    Kr,
    Manu.

Maybe you are looking for