Rows data will go side by side

Hi,
I have a table TEST in oracle 10g and under this there are rows like
account_code value
4142 300
4143 400
4144 500
Now I want data like this
4142 4143 4144
300 400 500
please help me to write the query.
Regards,
Jimut

Hi,
A query must have a fixed, known number of columns in its output. The number of columns and their names must be hard-coded when the qiuery is compiled.
You want a variable, unknown number of columns. You don't know the number or the names of the columns now, you want to get thos from the table itsel at run tme.
One way to get what you want is Dynamic SQL . This resolves the conflict of what must be known at compile time versus what is not known until run-time by delaying compile tme until run time. That is, the code you write today is not the query; it is code that will write and execute the query at some later date, using the data in the table at that date. There are dynamic SQL examples in the forum FAQ {message:id=9360005}
Another (simpler) work-around involves changing your requirements a little. Instead of getting a variable, unknown number of columns,you can get one big column, formatted to look like a variable number of columns. This is exactly what the <tt> SELECT ... PIVOT </tt> feature does when you tell it to generate XML output. The query actually produces 1 column of XML data, but, when it is displayed, it looks like a variable number of columns. Another way is String Aggregation , where we produce one big VARCHAR2 column that looks like a variable number of columns. The rest of this message shows an example of string aggregation.
Since you didn't post CREATE TABLE and INSERT statements for your own data (see the fm FAQ {message:id=9360002} ) I'll use the scott.dept table. The table actiually looks like this:
`   DEPTNO DNAME          LOC
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTONTo transpose this data so that it looks like this
OUTPUT
10             20             30             40
ACCOUNTING     RESEARCH       SALES          OPERATIONS
NEW YORK       DALLAS         CHICAGO        BOSTONwe can use a query like this:
WITH     cntr             AS
     SELECT     LEVEL     AS n
     FROM     dual
     CONNECT BY     LEVEL     <= 3     -- number of columns in orgiinal table
,     unpivoted_data     AS
     SELECT     d.deptno
     ,     DENSE_RANK () OVER (ORDER BY d.deptno)     AS deptno_rnk
     ,     c.n
     ,     CASE  c.n
              WHEN  1  THEN TO_CHAR (deptno)
              WHEN  2  THEN dname
              WHEN  3  THEN loc
          END     AS txt
     FROM        cntr     c
     CROSS JOIN  scott.dept  d
SELECT       REPLACE ( SYS_CONNECT_BY_PATH ( RPAD ( NVL (txt, ' ')
                                      , 14  -- Max column length
                               , '`~'          -- Never occurs in data
            , '`~'
            )     AS output
FROM       unpivoted_data
WHERE       CONNECT_BY_ISLEAF     = 1
START WITH     deptno_rnk     = 1
CONNECT BY     deptno_rnk     = PRIOR deptno_rnk + 1
     AND     n          = PRIOR n
ORDER BY  n
;This query will work in Oracle 10.1 (or higher).
It assumes we know how many columns in the original table we want to transpose (3 in this case, which will be the number of rows in the output), the maximum length we want to show for each item (14 characters in this case), and some sub-string that never occurs in any of the data ('`~' in this case). It does NOT assume we know the number of rows in the original table, which we be the number of "columns" in the output. In this eample, there are 4 rows that appear as 4 "columns", but the number 4 does not appear anywhere in the query.
Notice that there is only one real column in the output: a VARCHAR2 column called output. The column header that SQL*Plus supplies isn't helpful in this case, so we could suppress it using <tt> SET HEADING OFF </tt>. VARCHAR2 columns in Oracle SQL have a limit of 4000 chararacters , so if we display 14 characters for each "column", and have 1 character separating the "columns", then we can't have more than 266 "columns" in the output. Nobody would be able to read that many, anyway.
The query above can be modified so that the one output column looks more like a variable number of columns:
10             20             30             40
============== ============== ============== ==============
ACCOUNTING     RESEARCH       SALES          OPERATIONS
NEW YORK       DALLAS         CHICAGO        BOSTONYou could also add the original colum names as labels:
DEPTNO: 10             20             30             40
        ============== ============== ============== ==============
DNAME:  ACCOUNTING     RESEARCH       SALES          OPERATIONS
LOC:    NEW YORK       DALLAS         CHICAGO        BOSTONI'll leave these as execises.

Similar Messages

  • Displaying Two groups of data side by side

    We are using XML Publisher 5.6.2. We have a requirement where we need to display two independent groups side by side.
    What we tried was, we had a single table, on which on the same row, we defined the first group ( for-each:group1)<?Col1?><end-each>, in a single cell as part of three different form fields and then in the second column, we started the next group.
    But when we ran the report, the second group does not get dsiplayed. The workaround we have to use is that define the second group in a seperate row than the first group. This displayed the data for both the groups.
    The issue is that, if Group1 has 10 rows, then my second group will be pushed down.
    Has anybody had this issue and if there is a resolution, please let us know.
    Thanks,
    - Vasu K -

    hi this is mohan,
    I would Like to display the data in single table. i have 10 groups when i m trying the columns becoming null. when i m taking it in diff tables its working fine but my client is not satisfied with that is there any solution for this making it in one table.
    Regards&Thanks
    Mohan.katepalli
    Path Infotech Limited

  • Display data and iframe side by side

    Hi Experts,
    I have a requirement like to display the header and item details on left side of the page and another webpage using iframe tag on right side. How is it possible? I should not use the tabstrips.
    Can anybody please help me out how can I display the data and iframe side by side?
    Regards,
    Ranganadh.

    Hi Ranganadh,
    First you need to create a BSP page that holds the header and Item details(Let's say this as custom.htm).
    Secondly create a new page with frame set tag and call the custom.htm page and other webpage with URL.
    Sample coding will be like
    <%@page language="abap" forceEncode="html" %>
    <%@extension name="htmlb" prefix="htmlb" %>
    <htmlb:content design           = "classic+design2002+design2003"
                   controlRendering = "sap"
                   rtlAutoSwitch    = "true" >
      <htmlb:document>
        <htmlb:documentHead title="Testing for Frames" >
                 <frameset cols="50%,50%" framespacing="0" frameborder="0">
                   <frame name="menu" src="h t t p://www.google.com" scrolling="auto" noresize>
                   <frame name="main" src="h t t p://www.yahoo.com" scrolling="auto">
                 </frameset>
        </htmlb:documentHead>
      </htmlb:document>
    </htmlb:content>
    In the above code replace "http://www.google.com" with your custom.htm page
    Remove spaces between http and noresize will not allow user to resize the frame.
    Regards,
    Ravi
    Edited by: Ravi A on Mar 14, 2011 7:32 PM

  • No sap data found in the database SID !

    Hello All,
    While doing BI system copy activity, we are getting message as no sap data found in the database <SID>! and we could not able to proceed further.
    We have MS SQL 2005 as DB and Windows 2003 STD as our OS. We are doing the system copy through homogeneous system copy method (Backup / Restore).
    Before running SAPint we had deleted the old database then restored the database from the backup which we had taken of our production system.
    We also ran the SQL script user_change.sql as per the note # 551915 but in SAPint we are getting above mentioned error.
    Could you please help me in this regard ?
    Best Regards,
    Amit Vaij

    Hi at all, I have the same error. But I'm wondering about the assumption, that the schema renaming should be the root cause.
    I'm trying to copy a BI dual tack system on Windows/MSSQL database specific (http://scn.sap.com/thread/3380228)
    Now I'm defining the parameters in SAPINST (SoftwareProvMngr), so at the moment in no step I've to set up any old schema. Also I'm not at the step of defining the JAVA export.
    At the moment the SAPINST tool is trying to connect the main SAP DB.
    I attached and renamed the ABAP part of the DB. I will now try to detach the DB, I assume the SAPINST Tool will install to an empty DB. So if you attach a DB with a wrong schema it can not find any tables in the instance shema of the SID defined in SAPINST and it work... we will see...
    Detach was the wrong Idea... it seems there is any issue with the permissions...
    but R3trans -d works

  • External display mirrors but will not work side-by-side.  What is wrong?

    I am using a VIZIO HD TV as a second display . Setting the TV to 1920 x 1080 (it's max) and the iMac to 1920 x 1200, the two displays work correctly in the "Mirror" mode. When I set the "Arrangement" to side by side to create another display space, the TV displays the Invalid Mode error. The behavior does not improved when the two displays are set to lower resolution levels. This same TV works fine in all modes when connected as a second display to my Mac Book Pro.
    Any ideas?

    I apologize to everyone who is following this but I have a dilemma which I think Mr. Brody may be able to solve and I know of no way to contact him other than the forum.
    Mr. Brody, you may be the "Geek" (compliment) I am desperately looking for, No one in our area .. and AppleCare (on all three of my units) has no answer.
    I added an ASUS VH198T 19" monitor for viewing tutorials while working in Adobe Lightroom and Photoshop. DVI to mini for iMac. The ASUS runs at 60Khz and 1440x900 where the iMac is, of course 1680x1050. Each time the ASUS goes to sleep is closed, when it restarts, the iMac apparently sets it to one of it's standard resolutions 1600x900, unfortunately that's a little higher so I get flashing of the ASUS and ... WEIRD > Magic Mouse goes nuts with pointer jumping all over. Apple had a tech come by for the Mouse, wouldn't even consider the monitor, not an Apple product. Tech found nothing. I have talked with ASUS several times, they say it is the Mac and I now think they are right, especially after they sent me a replacement under terms of their warranty, very generous. It does the same! Both monitors work on our Xp Laptop, it lets me set the resolution to whatever I want.
    When 'mirrored' the resolution IS set to 1440x900, works fine when return to individual UNTIL the next time it sleeps or turned off. Any suggestion???
    Can Terminal allow a change from 1600 to 1440?? If so, how?? I'm not Linux or Unix literate, among other things.
    Will most gratefully appreciate,
    Ed in Pensacola

  • Position of the days and dates being on the right side of the day in the week calendar.

    I'm having a huge problem with the days and dates being on the right side of the day in the week calendar. Can I change that to the left upper side?
    it makes the whole schedule off balance you see.

    Thanks for stating that. So quickly. That *****. I also now see that more people have problems with this. Where can I complain?

  • When i zoom pic then coming some Black or wight boxes in image or when zoom agin they it will come in ohere side in picture pls solv this problom. this problom start when i update photoshop cc 2014

    When i zoom pic then coming some Black or wight boxes in image or when zoom agin they it will come in ohere side in picture pls solv this problom. this problom start when i update photoshop cc 2014

    in mac command-k
    preferences/interface/Workspace/Reset
    or in windows control-k
    preferences/interface/Workspace/Reset

  • How to show output in sqlplus side by side intead of in row

    in sqlplus if I type
    select A,B,C,D,E,F,G,H,I from SOMEHWERE where J='goat4';
    OUTPUT IS LIKE
    A B C D F
    G H I
    value here value here
    value here here
    tht is too hard to read
    how can I make it side by side
    like
    A Value here
    B Value here
    C Value here
    D Value here
    E Value here
    F Value here
    G Value here
    H Value here
    I Value here
    Thanks alot for help

    Numerous possibilities ... you can extent the linsize as already demonstrated but that has limited utility. The method I would suggest is formatting the column widths.
    Lots of demos here:
    http://www.morganslibrary.org/reference/sqlplus.html
    But this simple example should help.
    orabase> desc dba_data_files
    Name                                                                          Null?    Type
    FILE_NAME                                                                              VARCHAR2(513)
    FILE_ID                                                                                NUMBER
    TABLESPACE_NAME                                                                        VARCHAR2(30)
    BYTES                                                                                  NUMBER
    BLOCKS                                                                                 NUMBER
    STATUS                                                                                 VARCHAR2(9)
    RELATIVE_FNO                                                                           NUMBER
    AUTOEXTENSIBLE                                                                         VARCHAR2(3)
    MAXBYTES                                                                               NUMBER
    MAXBLOCKS                                                                              NUMBER
    INCREMENT_BY                                                                           NUMBER
    USER_BYTES                                                                             NUMBER
    USER_BLOCKS                                                                            NUMBER
    ONLINE_STATUS                                                                          VARCHAR2(7)
    orabase> col file_name format a30
    orabase> select file_name from dba_data_files;
    FILE_NAME
    C:\ORACLE\ORADATA\ORABASE\USER
    S01.DBF
    C:\ORACLE\ORADATA\ORABASE\UNDO
    TBS01.DBF
    C:\ORACLE\ORADATA\ORABASE\SYSA
    UX01.DBF
    C:\ORACLE\ORADATA\ORABASE\SYST
    EM01.DBF
    C:\ORACLE\ORADATA\ORABASE\EXAM
    PLE01.DBF
    C:\ORACLE\ORADATA\ORABASE\UWDA
    TA01.DBF
    6 rows selected.
    orabase> col file_name format a40
    orabase> /
    FILE_NAME
    C:\ORACLE\ORADATA\ORABASE\USERS01.DBF
    C:\ORACLE\ORADATA\ORABASE\UNDOTBS01.DBF
    C:\ORACLE\ORADATA\ORABASE\SYSAUX01.DBF
    C:\ORACLE\ORADATA\ORABASE\SYSTEM01.DBF
    C:\ORACLE\ORADATA\ORABASE\EXAMPLE01.DBF
    C:\ORACLE\ORADATA\ORABASE\UWDATA01.DBF
    6 rows selected.Note the control of the display width of the column. Without the formatting the column would display at 513 characters.

  • Problem accessing data from Destination: dest:FP_ICF_DATA_ SID //sap/bc/fp/

    This error message has many threads.  However, I have not seen any postings for NW CE 7.1.  The configuration for this version of JAVA and ADS is very different from any of the documentation that we have found.  We suspect a config issue but cannot find any pertinent documentation for ADS configuration and NW CE 7.1 (we are SP11). 
    Where can we find ADS configuration documentation for NW CE 7.1?
    Please help.
    So far, we are mainly using test FP_CHECK_DESTINATION_SERVICE which seems to prove that the destination configuration is the problem.  Fortunately, some of the configuration was automated. But not all.

    Thanks for the help, so far.  I have gotten one step closer by manually starting all processes and services related to Adobe Document Services.  CE 7.1 is quite a bit different.
    I can now get a byte count returned with the test FP_CHECK_DESTINATION_SERVICE in SE38 without checking the "with destination service" box.  When I check the box, I still get the "Problem accessing data from Destination: dest:FP_ICF_DATA_<SID>//sap/bc/fp/ message".
    The problem is related to the return of the rendering service from the Java side via the Java destination service.
    Note that the ABAP side with the problem is ECC 6.0 EHP3 SP1.

  • A Characteristci appears twice under the Rows Column on the left hand side.

    Hi All,
    According to the requirement , there are 2 Material Numbers ,1 of them is used for Compounding,which is not required in the Report,but as it is used for Compounding ,we need to place that in the rows.
    We have put tat in "NO DISPLAY" mode,but  Material Number appears twice under the Rows  column, on the left hand side of the screen, in the Portal when we execute the Report.How Can we have to display only 1 Material Number on the left hand side of the screen?
    Thanks in Advance,
    Sravani

    the left hand side of the screen is reakky vague....you should be more specific...
    Probably you need to filter out the compounding characteristics in the global filter area.
    Thanks...
    Shambhu

  • Printing data in Smart form side by side.

    Hi Abap Guru's,
                          I have data in internal table. i dont know how many records are there in it. I need to print the data, side by side in smart form.
    For example:
    Mr James was a member of the above-mentioned plan. you and <b>your children, Tom , jane , Harry and Michael,</b> are entitled to receive pension.
    > children must be printed side by side in smart form.
    Thank you in advance,
    -Anil

    Hi anil,
    In case you are having problems in finding the no of records in the internal table use the following command.
    DESCRIBE TABLE itab LINES w_lines.
    w_lines gives u the no of records.
    For further help u need to tell the structure of the internal table.
    Hope it is helpfull to u.

  • After updayting fire fox the applixation will not open I get a message that says the application failed to start because its side -by - side configureation is in correct. please see event log or use the command sxstrace.exe tool for more detail

    fire fox will not open

    See:
    *[[/questions/910134]]
    Seems to be caused by a corrupted Visual C++ installation (multiple versions can be installed side-by-side; SxS).
    You can try to use the sxstrace.exe tool to see if you can find which files are missing or corrupted and (re)install missing Visual C++ libraries.
    * http://www.vistax64.com/software/245768-side-side-configuration-incorrect.html
    * http://answers.microsoft.com/en-us/windows/forum/windows_7-pictures/error-the-application-has-failed-to-start-because/df019c0d-746e-42d0-ad68-465e18e3f3ef

  • What will Happen in R3 side while Replicating Datasource

    Hi Friends,
    what will happen in R3 side and BW side while replicating datasource in BW side
    Thanks & Regards,
    Gowri

    Hi Gowri,
    Replication needs to be done only when you change the extract structure which in turn would change your datasource. The simplest way to know when replication needs to be done is each time you save you datasource in R/3. This causes the timestamp of the datasource to be changed and hence the timestamp of the datasource in R/3 and BW are not in sync. Replication would make the timestamp in sync in both R/3 and BW.
    Hence you would notice the error "Timestamp error" when you do not replicate the datasource after changing it.
    Also check this link:
    Re: time stamp
    Bye
    Dinesh

  • Ever since I downloaded the new iOS 7 my screen will not turn up and down and it rotates on its own side to side.it will not face the way I want it to go. How do I fix it?

    Ever since I downloaded the new iOS 7 my screen will not turn up and down and it rotates on its own side to side.it will not face the way I want it to go. How do I fix it?

    I've been working on this all day!!! I've tried everything I know of and can't get it to load either. Sounds like lots of people are having problems. Here is what I have so far...I have uninstalled EVERYTHING on my pc from apple and reinstalled itunes to no avail. I have tried all sorts of things I've read as fixes online. NOTHING has worked. Here is something interesting that i have noticed though. my main pc (which is the one i have always managed my itunes account with for years) is a 32 bit system running windows 7. Yesterday I installed itunes for the first time on my new netbook which is a 64 bit (windows 7) system and it works just fine. i have three other laptops (all window 7) in my household that are all 64 bit operating systems and ALL have updated to 10.5 and THEY ALL work fine. this is FOUR 64 bit systems ALL updated w/10.5 that work and ONE that is a 32 bit that will not. Can't get any help from apple. their suppot *****! I want to get someone on the **** phone or a live chat but cant. *** APPLE????? please let mw know if you find SOMETHING i can try next. I'm out of ideas and patience!

  • Is there an app for iPad which will allow me to read 2 books at the same time? 2 Books side by side.

    Is there an app for iPad which will allow me to read 2 books at the same time? 2 Books side by side. For example, one in English and the same book in Swedish. I'd use this in helping me to learn different languages. Any help would be appreciated.
    Regards,
    LB

    Have you searched for one? This is a technical forum. Look for what you want at the iTunes Store.

Maybe you are looking for