By turning the result of the query 'on his side' (horizontal of vertical rows of OCOL)

Let's say I'm doing something like "SELECT * FROM DBA_TABLES WHERE TABLE_NAME = 'BLAH' AND OWNER = 'someone ';

Unless I have an incredibly wide monitor, there is no way that output is going to be pretty.

Is there way to say well "for this query, flip out of row/column,' thus, it comes like this, with the head down in the first column and the lines left for the following columns to the right:

OWNER SOMEONE
TABLE_NAME BLA
NOM_TABLESPACE DATA01
CLUSTER_NAME
IOT_NAME
VALID STATE
< etc >

I can do this with dbms_output.put_line in PL/SQL, etc., but I wonder if there is a general way to do this in SQL.

Hello

Display multiple columns of a row as if they were a single column on several lines, called Unpivoting .
Like so many other things, how to do it in Oracle depends on what version of Oracle you have. Starting Oracle 11, there's a handy SELECTION... Function of the UNPIVOT operator. In any version, you can join table with data containing n columns with a table that contains n lines and an expression BOX (or DECODE) allows to display different data on each line of output.

Search for "Unpivot" or "Columns in lines" for examples.

As Damorgan said, there is no easy way to do it, and there is not much easier if you have more than 1 line of original data. Your time is probably better spent formatting the output of a line to make it more readable.

Tags: Database

Similar Questions

  • Turn the query into a GROUP BY

    I'm turning the query below, so he produced the first line of each user, each combination of responsibility:

    Select a.LOGIN_ID, a.START_TIME, a.END_TIME, c.RESPONSIBILITY_NAME, b.USER_ID, d.USER_NAME in the FND_LOGIN_RESPONSIBILITIES,
    fnd_logins b,
    FND_RESPONSIBILITY_tl c,
    fnd_user d
    where
    a.LOGIN_ID=b.LOGIN_ID
    and a.RESPONSIBILITY_ID=c.RESPONSIBILITY_ID
    and b.USER_ID=d.USER_ID
    order by d.user_name, c.responsibility_name, a.end_TIME desc nulls last
    For a unique combination of the user and the responsibility, it should only return the first value. Currently it is multiple outputs back int the format:
     LOGIN_ID START_TIM END_TIME  RESPONSIBILITY_NAME                                        USER_ID USER_NAME
    ---------- --------- --------- ------------------------------------------------------- ---------- -------------------------------------------------------
       1487207 23-NOV-11 23-NOV-11 XXX  Payables Supervisor                                1236 ZZZ
       1487207 23-NOV-11 23-NOV-11 XXX  Payables Supervisor                                1236 ZZZ
       1480785 22-NOV-11 22-NOV-11 XXX  Payables Supervisor                                1236 ZZZ
       1478246 22-NOV-11 22-NOV-11 XXX  Payables Supervisor                                1236 ZZZ
       1478246 22-NOV-11 22-NOV-11 XXX  Payables Supervisor                                1236 ZZZ
       3149187 14-DEC-12 14-DEC-12 XXX Imprest Employee Responsibility                           5825 
       3136830 11-DEC-12 11-DEC-12 XXX Imprest Employee Responsibility                           5825 ZZZ
       3102226 03-DEC-12 03-DEC-12 XXX Imprest Employee Responsibility                           5825 ZZZ
       3094387 30-NOV-12 30-NOV-12 XXX Imprest Employee Responsibility                           5825 ZZZ
       3094387 30-NOV-12 30-NOV-12 XXX Imprest Employee Responsibility                           5825 ZZZ
       3093463 29-NOV-12 29-NOV-12 XXX Imprest Employee Responsibility                           5825 ZZZ
       3090327 29-NOV-12 29-NOV-12 XXX Imprest Employee Responsibility                           5825 ZZZ
    This should only output as below:
     LOGIN_ID START_TIM END_TIME  RESPONSIBILITY_NAME                              USER_ID USER_NAME
    ---------- --------- --------- ------------------------------------------------------- ---------- -------------------------------------------------------
     1487207 23-NOV-11 23-NOV-11 XXX  Payables Supervisor                                1236       ZZZ
     3149187 14-DEC-12 14-DEC-12 XXX Imprest Employee Responsibility                   5825      ZZZ
    My version of the database is 11.2.0.2.0

    James

    A way

    select *
    from
    (
    select      a.LOGIN_ID,a.START_TIME,a.END_TIME,
         c.RESPONSIBILITY_NAME,b.USER_ID,d.USER_NAME,
         row_number() over(partition by d.user_name, c.responsibility_name
                         order by a.end_TIME desc nulls last ) rn
    from      FND_LOGIN_RESPONSIBILITIES a,
         fnd_logins b,
         FND_RESPONSIBILITY_tl c,
         fnd_user d
    where a.LOGIN_ID=b.LOGIN_ID
    and a.RESPONSIBILITY_ID=c.RESPONSIBILITY_ID
    and b.USER_ID=d.USER_ID
    )
    where rn = 1
    order by user_name, responsibility_name
    
  • Windows 7 update everytime I open Chess Titans I have to turn the Board at my side. I'm black and it opens always white, take the 1st pass and remains there unless I smile it 180 degrees

    original title: Chess Titans little Caprice

    Windows 7 update everytime I open Chess Titans I have to turn the Board at my side. I'm black and it opens always white, take the 1st pass and remains there unless I smile it 180 degrees.

    Hi Woody15380,

    Chess Titans walk and check if that helps
    .
    Use this link to turn off the game and then turn on again.
     
    Also delete all the files in C:\Users\user name\AppData\Local\Microsoft Games\Chess Titans
     
    Aziz Nadeem - Microsoft Support
  • Help turn the query that returns single return system

    Hello, I have two tables, readings, and values. Values have a foreign key to the readings.
    create table readings 
    (
    id number primary key,
    point number,
    datereading date
    );
    
    create table reading_values
    (
    id number primary key,
    counter_nr number,
    point number,
    reading_id number,
    datereading date,
    CONSTRAINT fk_reading
    FOREIGN KEY (reading_id)
    REFERENCES readings (id)
    );
    The point and datereadings columns have the same value of related rows.
    insert into readings values (1, 1234, to_date('20100622 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (1, 0, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row1
    insert into reading_values values (2, 1, 1234, 1, to_date('20100622 12:12', 'yyyymmdd HH24:MI')); --row2
    
    insert into readings values (2, 1234, to_date('20100623 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (3, 0, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row3
    insert into reading_values values (4, 1, 1234, 2, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row4
    
    insert into readings values (3, 1111, to_date('20100621 12:12', 'yyyymmdd HH24:MI'));
    insert into reading_values values (5, 0, 1111, 3, to_date('20100623 12:12', 'yyyymmdd HH24:MI')); --row5
    Now I have the procedure which the entry: p_point and p_date.
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < p_date and point = p_point
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    so I want the previous reading_values (in time based on p_date) for a certain point p_date. I hope this makes sense?
    Example:
    select * from reading_values rv, 
    (select * from (select id, datereading
    from readings where datereading < to_date('20100624 12:12', 'yyyymmdd HH24:MI') and point = 1234
     order by datereading desc) where rownum <= 1) t where rv.reading_id = t.id
    
    returns row 3 and 4
    Now, what I want to do, is replace p_point and p_date with two collections. For example: p_points = [1234, 1111] p_dates = [20100622 15:12, 20100624 12:12]
    Here, I want to have the previous reading_values by point = 1234 and datereading < 20100622 order 15:12 by datereading (where rownum < = 1).

    and also reading_values by point = 1111 and datereading < 20100624 order 12:12 by datereading (where rownum < = 1).

    This should return line1, line2 and row5...

    So far I came up with this. But I can't be sure that it is correct. And the performance seems to be horrible (cost 88, 13 recursive calls, 155 becomes uniform) for a query with 2 entry points and 2 dates compared to the original to just a single point query and the date of entry (cost 13, 1 recursive call and gets 14 coherent).
    Select rv.* from (SELECT r.id
          FROM    Readings r, 
          (select rownum rn1, t1.id from table1 t1 order by id) t1, -- input parameter1 (point collection)
          (select rownum rn2, t2.date_now from table1 t2 order by id) t2  -- input parameter 2 (date collection)
          WHERE  r.point = t1.id
              AND     r.datereading = (SELECT  max(r2.datereading)
              FROM   Readings r2
                WHERE   r2.point = t1.id
                AND     r2.datereading < t2.date_now AND rn1 = rn2)
        ) r, Reading_Values rv where r.id= rv.reading_id;
    code for creating table 1 that I used instead of collections of entry:
    create table table1
    (
     id number not null primary key,
     date_now date not null
    );
    insert into table1 values (1234, to_date('20100622 15:12', 'yyyymmdd HH24:MI'));
    insert into table1 values (1111, to_date('20100624 12:12', 'yyyymmdd HH24:MI'));
    Hope someone can help me on my way :) Please ask if something is unclear or strange! Thank you!

    Published by: KarlTrumstedt on 23-jun-2010 06:20

    Try this

    SELECT RV.ID, RV.COUNTER_NR, RV.POINT, RV.READING_ID, RV.DATEREADING
    FROM (
        SELECT (    SELECT LAST_VALUE(RE.ID) OVER
                         (PARTITION BY RE.POINT ORDER BY RE.DATEREADING)
                    FROM READINGS RE
                    WHERE RE.DATEREADING < T1.DATE_NOW AND RE.POINT = T1.ID
                ) ID,
                T1.ID POINT,
                T1.DATE_NOW
        FROM TABLE1 T1
    ) X
    JOIN READING_VALUES RV
    ON (X.ID = RV.READING_ID AND X.POINT = RV.POINT)
    ;
    
  • I can't turn the phone on its side to see an overview

    When I turn my phone on its side, the image remains in the vertical format. How can I reset phone so that the images change when the phone is in the horizontal position?

    Use access control and turn it to portrait orientation lock. It will be the icon with the lock and the arc around him.

  • my monitor displays properly, the blue and yellow lines horizontally and vertically on the screen

    monitor the display that is not right, when you move the slider it filled with blue, there are blue lines across screen

    Hello

    1 did you changes to the computer before the show?

    2. the make and model of the computer/monitor?

    Note: Make sure that the cables are connected properly to the screen and try replacing the monitor cable and/or monitor itself.

    Method 1:
    Resources for troubleshooting problems in Windows XP
    http://support.Microsoft.com/kb/307960

    Method 2: Uninstall and reinstall the display drivers and see if that helps.
    (a) click Start, right click on computer.
    (b) click on properties, click on Device Manager
    (c) expand the graphics card, right click on the map
    (d) click on uninstall
    (e) now go to your computer/device manufacturer site, download the updated drivers and install them.

  • Add a string when the query returns all records

    DB version: 11.2

    create table t (empname varchar2 (25), salary number, varchar2 (20) months, number of over_time);

    insert into values t ('JOHN', 2000, "NOVEMBER2014", 0);

    insert into values t ('KATE', 2000, "NOVEMBER2014", 300);

    insert into values t ('HANS', 5000, "NOVEMBER2014", 100);

    insert into values t ("KRISHNA", 2500, "NOVEMBER2014", 0);

    insert into values t ("SIEW", 3000, "NOVEMBER2014", 0);

    commit;

    SQL > select * from t;

    EMPNAME MONTHS SALARY OVER_TIME

    ------------------------- ---------- -------------------- ----------

    JOHN 2000 NOVEMBER2014 0

    KATE 2000 NOVEMBER2014 300

    HANS 5000 NOVEMBER2014 100

    KRISHNA 2500 NOVEMBER2014 0

    SIEW 3000 NOVEMBER2014 0

    SQL > select * from t where MONTH = 'NOVEMBER2014' and OVER_TIME! = 0 ;

    EMPNAME MONTHS SALARY OVER_TIME

    ------------------------- ---------- -------------------- ----------

    KATE 2000 NOVEMBER2014 300

    HANS 5000 NOVEMBER2014 100

    What I need is:

    If the query above returns at least one record, it should display the line ' Yes. We have one or more employees who worked overtime in November2014'

    before the documents are printed

    Thus, the expected production is

    Yes. We have one or more employees who worked overtime at the November2014

    EMPNAME MONTHS SALARY OVER_TIME

    ------------------------- ---------- -------------------- ----------

    KATE 2000 NOVEMBER2014 300

    HANS 5000 NOVEMBER2014 100

    If the query returns no records then usual 'no rows selected' isn't enough

    Lothar G.f. says:

    In fact, sql * more is no good tool for use considered.

    Really?  It may be a good reporting tool if you learn to use it as such...

    for example

    SQL > ttitle left 'Yes. We have one or more employees who worked overtime in November2014.
    SQL > select * from emp where empno = 1234;

    no selected line

    SQL > select * from emp where empno = 7788;

    Yes. We have one or more employees who worked overtime at the November2014
    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
    ---------- ---------- --------- ---------- -------------------- ---------- ---------- ----------
    7788, SCOTT, ANALYST, 7566 19 APRIL 1987 00:00:00 3000 20

    This is just a basic example.  It is possible to get SQL * more to ask for the required criteria and that the title could adjust according to this criterion, as well as the query building on it also.

    However, the OP did not specify SQL * as the reporting tool, so there is little interest providing a complete solution which, until they specify what user interface that they are actually using.

  • When, on my home page, I click on the link "transparent popup" in the query "did you mean: transparent popup", NO RESULTS appear in this new tab; How to solve?

    I had trouble due, apparently, to a file named popuptransparent [dot] xul, which I have 3 cases on my computer (Win XP/Firefox last v.). Using my window of AVG home page, I get "popuptransparent" (try to fix) and the results appear OK. But then when I click to a new tab, on the "transparent popup" link in the query "did you mean: transparent popup", NO RESULTS appear in this new tab. In addition, when I reload then the Panel of AVG which sought to 'popuptransparent' in the first place, it, too, shows now no results. Or a panel shows Google now no results. They show the quantity of results, but just white screens for the results themselves.

    Links https://support.mozilla.org/en-US/questions/948804?esab=a & as = aaq and https://support.mozilla.org/en-US/questions/952141?esab=a & as = aaq brings me. I re-installed Firefox v. 20.0.1 nothing works. How to fix?

    Should I remove it from my computer all 3 of these instances of xul [dot]?

    Regarding the problem of searching, you can check the extension "Disconnect"? I think it could affect the Google sites and third parties who use Google. You can disable or try its button Options here:

    Firefox orange (or the Tools menu) button > addons > Extensions category

    While you're there, you can disable all extensions essential and unrecognized. When in doubt, turn off.

    After restarting Firefox, did you notice a difference?

    Could you explain in more detail the next part?

    Should I remove it from my computer all 3 of these instances of xul [dot]?

    Is this something that came in a security sweep? What question do you think they are originally? They are located in a folder extensions?

  • Is there a way to combine their results of the query in a single function

    I have a bunch of functions that return a query:

    < cffunction = access "getDeals" name = "remote" returntype = "query" >
    < cffunction = access "getDeals2" name = "remote" returntype = "query" >

    is there a way to combine their results of the query in a single function that returns a structure of different results?

    Uh, it is probably more suited to a table - effectively turning it into a list of queries. Then you loop the array and each output.

    I use a similar approach in the creation of the system of the user messages. Most of my functions that are called do their part, then at the end call another function, I called 'messages '. This function takes all what my function sends and adds it to a message board.

    Keeps me out of a long list of messages - because I could call several functions at the same time. If I have just the output of a message of each function, each would crush the other. So, I'd get one message at a time.

    Immediately after that he was released, I will destroy it then the message table so that messages are not kept inside.

    Mikey.

  • I need to stop a download of the query, I thought a stand-alone application but turns require a higher level (FCPX) as a 'parent' and I do not who have, or want to buy.

    I need to stop a download of the query, that I thought a stand-alone application but turns require a higher level (FCPX) as a 'parent' and I do not have that, or I want to buy it.

    Motion IS a stand-alone application. It is mainly designed to make effects for Final Cut Pro X, but it is not necessary to have with FCPX nor is it necessary to have FCPX to create projects for other purposes. When you open the query, simply select project of work outside the FCPX motion. You can save regular projects of Motion anywhere on your system.

  • Refresh the result table or rerun the query

    I have a requirement, simple but stuck somewhere.

    Jdev 11.1.1.17 Expert level: Mid-Senior

    I have a form of application and the associated result table. It works great and no problems.

    My requirement is that I have a commandlink on one of the column. Clicking on that will open a popup with an editable filed. OK will commit and Cancel will close the pop-up window.

    After that the popup is dismissed with partial trigger, my table refreshes but data is identical to the front. But if I click the Find (Search) button on the query, it shows the data with the results updated which are changed in the pop-up window above.

    How do I update table which re - runs the query and then refreshes the table after the popup is dismissed, or when the user clicks the OK button in the pop-up window.

    Get on the viewObject of this table and call the executeQuery method that

    Write this method in the method AMImpl and then call it in bean managed using the OperationBinding at the click on the Ok button of the dialog box

    ViewObject vo = this.getViewObjectName ();

    vo.executeQuery ();

    Ashish

  • Need to print the results of a query in a CASE statement

    I want to print the results of a query in a CASE statement:

    SELECT RUN_STATUS

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where START_TS >

    (sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e

    The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.

    If I execute this statement, it throws an error stating:

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: 1 column: 96

    How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.

    Thanks in advance!

    Hey guys,.

    I found the solution:

    SELECT

    RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0

    THEN "NO JOB RAN.

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where

    START_TS > (select sysdate - XXAFL_MINUTES MINUTE))

    where

    RUN_STATUS is not null;

    The output:

    NO JOBS RAN AFTER 09:07:54

    Thanks to you all!

  • How to get SQL Developer 4.1 to display the query result?

    SQL DEV 4.0.3.16.84 execution of a SELECT statement is stored in a .sql file causes the window of the query result of pop-up indicating the result of a SELECT statement.  SQL DEV 4.1 is not to do so.

    Oops on my part; my SQL formatting has been the root cause.  I got used to insert split without any character of comment lines in front of them.  For example:

    ==================================================

    Select funny business;

    The foregoing indicates the behavior described.

    --==================================================

    Select funny business;

    With the dash double comment shows, the SQL works very well.

    This is different than previous versions of SQL Developer, but is probably better functionality.  I'll try to mark it as answered, but anyone with the admin should certainly do so if I can't.

  • Need help to understand the query result

    Hi gurus

    I was reading one of the question here in this forum and its link is below:

    Query required for scenario

    I had some confusion related to this code and don't understand the logic of the out put, see query below:

    Query

    with sub_services as

    (

    Select su_seq 12323, 'HLR1' so_id, 1 seq Union double all the

    Select su_seq 12323, "HLR2' so_id, seq 2 Union double all the

    Select su_seq 12323, "A09" so_id, seq 3 of all the double union

    Select su_seq 12333, "MO1" so_id, seq 4 Union double all the

    Select su_seq 12333, "MO2' so_id, seq 5 Union double all the

    Select su_seq 12333, "A09" so_id, 6 seq in union double all the

    Select su_seq 12333, 'M0CR' so_id, seq 7 Union double all the

    Select su_seq 12999, "LOL1' so_id, seq 8 Union double all the

    Select su_seq 12999, "LOL2' so_id, seq 9 double

    )

    Select *.

    of sub_services b

    where exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    )

    order by 2;

    The query result

    12323 A09 3

    12333 6 A09

    12323 HLR1 1

    12323 HLR2 2

    12333 M0CR 7

    12333 4 MO1

    12333 5 MO2

    According to my understanding, the above query should return records in red only because of her is below command

    It exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    but don't know why he's back 7 files, can someone help me understand the result...

    It is query is functionally identical to the PL/SQL block, but much more effective.

    declare

    number of l_res;

    Start

    for line (select *)

    sub_services) loop

    Start

    Select 1 from l_res

    of sub_services

    where su_seq = row.su_seq and

    so_id = "A09" and

    rownum = 1;

    exception when

    NO_DATA_FOUND then

    null;

    end;

    end loop;

    end;

    Essentially every row in the outer query are tested against him exists query.  Given the correlation between two requests is based only on su_seq each line with a su_seq value returned by him is returned in the output.

    Another way to think he uses instead a join condition.  This query is equivalent to the query to exist

    Select the main

    of main sub_services

    Join select (separate su_seq

    of sub_services

    where so_id = "A09") cond

    We main.su_seq = cond.su_seq;

    John

  • ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    Hello!

    I have a simple object type and a proecdure in which I am trying to use it to insert into another table

    -object

    CREATE ORREPLACETYPEmt_mtg ASOBJECT

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    CREATE ORREPLACETYPEREF_MTG ASTABLEOFMt_MTG ;

    -same structure as the use of sampletbl target table in the cursor query

    create table tbl_MT_MTG

    (

    ACOL NUMBER ,

    BCOL NVARCHAR2 (100)

    );

    -procedure

    CREATE ORREPLACEINTERIORTEST_PROCEDURE1

    AS

    ref_cur sys_refcursor ;

    REFR ref_mtg ;

    BEGIN

    OPEN ref_cur FOR

    Select acol,

    BCOL

    DE sampletbl rownum<10;

    Fetch ref_cur in bulk collectintorefr;

    Insert intotbl_MT_MTG(acol,bcol)selectacol,bcol fromtable(refr);

    commit;

    CLOSE Ref_cur;

    END;

    /

    When I run this procedure fails with

    ORA-06504: PL/SQL: return variables of the game results or the query types do not match

    ORA-06512: at "TEST_PROCEDURE1", line 10

    ORA-06512: at line 2

    Any help on this please...

    Thanks to an OLD POST below

    so perfect helped me! Thank you

    Tubby

    After 5 years of more :-)

    How to store refcursor in collection How to store refcursor in collection

Maybe you are looking for