Result of query tree

Hi all
Have a sample like this:
WITH  view1 as (
select 'SPLNMR31S51F241O' col1,'P3'  col2, '201068000011' col3, 'VPNE'  COL4 from dual union all
select 'SPLNMR31S51F241O' col1,'P3'       , '201068000015' , 'VPNE'   from dual union all
select 'SPLNMR31S51F241O' col1,'P3'       , '201068000015' , 'EGAS'   from dual union all
select 'SPLNMR31S51F2411' col1,'P1'  , '201068000016' , 'V001'   from dual union all
select 'SPLNMR31S51F2411' col1,'P1'  , '201068000016' , 'VPNE'   from dual union all
select 'SPLNMR31S51F2411' col1,'P4'  , '201068000018' , 'V001'   from dual
  )

select * from view1;

SPLNMR31S51F241O     P3     201068000011     VPNE
SPLNMR31S51F241O     P3     201068000015     VPNE
SPLNMR31S51F241O     P3     201068000015     EGAS
SPLNMR31S51F2411     P1     201068000016     V001
SPLNMR31S51F2411     P1     201068000016     VPNE
SPLNMR31S51F2411     P4     201068000018     V001
Can I create a query to achieve a similar result a tree, about like that
SPLNMR31S51F241O
  P3
   201068000011
    VPNE
   201068000015
    VPNE
    EGAS
SPLNMR31S51F2411
  P1
   201068000016
    V001
    VPNE
   201068000018
  P4
    V001
It's
COL1
   COL2
      COL3
         COL4
COL1
   COL2
      COL3
         COL4
Thanks for any help

Hello

Which produces the results you want unisng GROUP BY:

SELECT       CASE  1
          WHEN  GROUPING (col2)      THEN        col1
          WHEN  GROUPING (col3)      THEN  '  ' || col2
          WHEN  GROUPING (col4)     THEN  '    ' || col3
                         ELSE  '      ' || col4
       END     AS data
--     , col1, col2, col3, col4
FROM       view1
GROUP BY  GROUPING SETS ( (col1, col2, col3, col4)
               , (col1, col2, col3)
               , (col1, col2)
               , (col1)
               )
ORDER BY  col1
,       col2     NULLS FIRST
,       col3     NULLS FIRST
,       col4     NULLS FIRST
;

This requires that col1, col2, col3 and col4 are never NULL.

To understand the query works, it can help to a comment the last line of the SELECT clause:

,      col1, col2, col3, col4

The main problem with your GROUP BY query shown was that you were the CONSOLIDATION OF individual columns, so you have only one exit line to col4 = "VPNE" (for example). But you want a line of separate output for each line where col4 = 'VPNE' if the other columns are different. For example, the correct results have a line 'VPNE' as col3 = 201068000011, another at 201068000015 and another at 201068000016.
Published by: Frank Kulash, July 9, 2010 10:39

Published by: Frank Kulash, July 9, 2010 10:46

Tags: Database

Similar Questions

  • APEX 5 query tree area

    Hi all

    I am trying to build a region of the tree. I'm not an expert with who. I had the design of table like this:

    ,
    ID Name1 name2 Name3name4
    1Top_aTop_bTop_cTop_d

    How can I build a tree like these (with any default template that can expand/collapse)?

    Top_a

    Top_b

    Top_c

    Top_d

    Please share ideas if someone did!

    Thank you

    Nabila

    Thanks for your advice.

    In fact, I can't change the structure of the table. I only works at the front end.

    By the way, I solved using unpivot to build my as hierarchical query and I also implemented APEX DTree region plugin to add additional columns to show with tree node. My modified query is:

    SELECT THE LEVEL,

    name_value,

    contract,

    Recon,

    difference

    DE)

    Select distinct column_name, regexp_substr (Column,'[[: digit:]] + [[: space:]] *') col_level, name_value;

    regexp_substr (Column,'[[: digit:]] + [[: space:]] *')-1 p_level

    from my_table

    UNPIVOT

    (

    name_value for col_name (name1, name2, Name3, name4, name5, NAME6, Marque7, NAME8, NAME9, NAME10, NAME11, NAME12, NAME13, NAME14, name15)

    )

    Union of all the

    Select 'Difference', ","Difference", 0

    of the double

    ) accounts.

    (select recon, contract of)

    Select bookvalue, source_data

    from my_table

    )

    Pivot

    (

    Sum (Bookvalue)

    for source_data ("recon" as recon, 'contract' under contract)

    )

    ) reconciliation

    START WITH p_level = 0

    CONNECT BY PRIOR Col_level = p_level

  • How to modify data in "Result grid query" in Oracle SQL developer

    Dear,

    I would like to know how to change values directly in the query result grid.

    I use Oracle SQL Developer version 4.0.3.16

    Thank you

    Khalil

    EditValues.JPG

    I checked in SQL Developer 4 and I found no option to do this.

    I don't think it's available. You can open the table and add filters on each column and change. Or you can add where clause as suggested the link written by Jeff that I already gave. (http://www.thatjeffsmith.com/archive/2013/06/sql-developer-im-looking-at-a-record-how-do-i-edit-it/)

    Or you write update instructions.

    See you soon

    AJ

  • query tree Info

    I have a scenario where I need to create a hierarchical tree with no hierarchical data.

    Appreciate your help in this:

    Table structure:

    TAB_A

    =====

    col_id Column col_for col_cat

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

    A test1 1 CATA

    B test1 1 CATB

    C CISC 2 test2

    Test3 D 2 CTAC

    E test4 CATD 2

    F test5 CATD 2

    G test6 CATE 3

    Test7: 4 CATE

    The output of tree structure should be like:

    (first level of grouping - col_for)

    second group level - col_cat

    third level of grouping - Column)

    ===========

    1

    | _ CATA

    | _ test1

    | _ CATB

    | _ test1

    2

    | _ CISC

    | _ test2

    | test3 _____

    | _ CATD

    | _ test4

    | _ test5

    3

    | _ CATE

    | _ test6

    4

    | _ CATE

    | _ test7

    Receive your answer on that.

    Thanks in advance.

    Hello

    Here's an example of how you can use the update ROLLUP.  I use the table scott.emp, because I don't have a copy of your table. This query:

    SELECT deptno, job, ename
    FROM scott.emp
    ORDER BY deptno, job, ename
    ;

    shows the raw data into scott.emp:

    DEPTNO EMPLOYMENT ENAME
    ---------- --------- ----------
    10 REGISTRAR MILLER
    MANAGER 10 CLARK
    10. THE PRESIDENT KING
    20 ANALYST FORD
    20 ANALYST SCOTT
    THE CLERK 20 ADAMS
    20 CLERK SMITH
    20 MANAGER JONES
    JAMES CLERK 30
    30 MANAGER BLAKE
    ALLEN SALESMAN 30
    SELLER 30 MARTIN
    30 SELLER TURNER
    WARD SALESMAN 30

    Say we want to display this data as a hierarchy, where deptno is the parent of employment and employment ename parent, like this:

    DEPTNO EMPLOYMENT ENAME
    ---------- --------- ----------
    10
    CLERK
    MILLER
    MANAGER
    CLARK
    PRESIDENT
    KING


    20
    ANALYST
    FORD
    SCOTT
    CLERK
    ADAMS
    SMITH
    MANAGER
    JONES
    30
    CLERK
    JAMES
    MANAGER
    BLAKE
    SELLER
    ALLEN
    MARTIN
    TURNER
    WARD

    One way to do that is:

    SELECT THE CHECK BOX
    WHEN you GROUP (employment) = 1
    THEN deptno
    END AS deptno
    CASE
    WHEN you GROUP (ename) = 1
    THEN work
    Work AS
    ename
    FROM scott.emp e
    GROUP BY deptno
    ROLLUP (job, ename)
    ORDER BY e.deptno
    , e.job the FIRST NULLS
    , e.ename the FIRST NULLS
    ;

  • Choice of the message can be changed in the table of search results Simple query region?

    Hi friends,

    I have a Simple search query region in 11i.

    I created the SearchVO and bound to the query Table Region.

    I have two attributes MessageStyleText and a MessageChoice attribute in the simple search criteria.

    Search results show very well for all attributes.

    But when I search with the criteria of MessageChoice, in the table of results, this attribute MessageChoice is indicated as editable, display the drop-down list.

    I did this attribute ReadOnly = True but then it becomes readonly in search also. So this dosent help.

    I need to this drop-down list of MessageChoice be modifiable in the search criteria, but read in the table of results.

    Please help me with the resolution. Its kinda urgent.

    Would appreciate any help.

    Thank you

    Rajesh

    He solved.

    Added programmatically in code.

    Kept the attribute as MessageChoice in the query Table Region.

    Added to the controller

    ' Public Sub processRequest (pageContext OAPageContext, OAWebBean webBean)

    {

    super.processRequest (pageContext, webBean);

    OAM OAApplicationModule = pageContext.getRootApplicationModule ();

    OAMessageChoiceBean = processFlagMessageChoice

    (OAMessageChoiceBean) webBean.findChildRecursive ("AttributeId");

    processFlagMessageChoice.setReadOnly (true);

    }

  • Exclusive results of query

    CUSTOMER_ID            NAME
    100                   ANDREW
    200                   JAMES
    300                   SMITH
    400                   STEPHEN
    500                   OSCAR
    600                   JEAN
    700                   PADILLA
    800                   ROMANO
    ADDR_ID                  ADDR1          CITY          STATE         ZIP_CODE       CUSTOMER_ID
    110               ANDY ST             ABCD          PA          17102          100
    111               AY ST          BCD          NJ          08837          100
    112               NDY ST          ABCDE          NM          87102          100
    210               BW1 ST          ABCD1          NJ          08837          200
    211               BW2 ST          ABCD2          OH          81837          200
    212               BW3 ST          ABCD3          SC          91837          200
    213               BW4 ST          ABCD4          NC          21837          200
    214               BW5 ST          ABCD5          NJ          08837          300
    215               BW6 ST          ABCD6          OH          81837          300
    216               BW7 ST          ABCD7          SC          91837          300
    217               BW8 ST          ABCD8          PA          21837          300
    218               BW9  ST             ABCD9          NJ          08817          400
    219               BW10 ST             ABCD10             NY          81837          400
    220               BW11 ST             ABCD11             LA          91837          400
    221               BW12 ST             ABCD12             CA          21837          400
    222               BW13 ST             ABCD13             NJ          08817          500
    223               BW14 ST             ABCD14             NY          81837          500
    224               BW15 ST             ABCD15             LA          91837          500
    225               BW16 ST             ABCD16             CA          21837          500
    Hi all

    I have the above tables and I want back the customers who lived exclusively outside of a given State (SAY in Pennsylvania), which means that my query must return customers with ID 200, 400 and 500

    I wrote the following query:
    SELECT TA.CUSTOMER_ID, TA.STATE FROM T_CUSTOMER TC, T_ADDR TA 
    WHERE TC.CUSTOMER_ID = TA.CUSTOMER_ID AND 
    TA.CUSTOMER_ID NOT IN (SELECT TA.CUSTOMER_ID FROM T_ADDR TA WHERE UPPER(STATE)='PA') AND 
    TA.CUSTOMER_ID IN (SELECT TA.CUSTOMER_ID FROM T_ADDR TA WHERE UPPER(STATE)!='PA');
    This query retrieves the results, but I want to know:
    (1) is this request in itself good enough, in terms of performance, because I'm going to hit the tables that have millions of records (assuming that all appropriate indexes are in place)
    (2) is there a better way to write this query?

    To make it easier to view the data, here is where all customers have lived:
    100     NJ,     NM,     PA
    200     NC,     NJ,     OH,     SC
    300     NJ,     OH,     PA,     SC
    400     CA,     LA,     NJ,     NY
    500     CA,     LA,     NJ,     NY
    So, since 100 and 300 customer_ids lived in PA, I don't want to not those in results.
    Thanks in advance
    Shravan

    Customers who never lived in PA:

    SELECT  CUSTOMER_ID
      FROM  T_ADDR
      GROUP BY CUSTOMER_ID
      HAVING COUNT(CASE STATE WHEN 'PA' THEN 1 END) = 0
    /
    

    Customers who never lived in PA and they lived in the States:

    SELECT  CUSTOMER_ID,
            STATE
      FROM  (
             SELECT  CUSTOMER_ID,
                     COUNT(CASE STATE WHEN 'PA' THEN 1 END) OVER(PARTITION BY CUSTOMER_ID) PA_CNT
               FROM  T_ADDR
            )
      WHERE PA_CNT = 0
    /
    

    SY.

  • JavaScript Confirm box depends on the results of query

    Hello

    I use Apex version 3.2.1 and I'm looking for a way to do the following, any help much appreciated:

    A javascript confirm will appear when the user sends a page if the result of a query returns something, the query should look like this...

    SELECT * FROM LINKEDPROJECTS
    WHERE ENV_ID =: P18_ENV_ID
    AND ID_COMP =: P18_COMP_ID
    AND DATE_FROM < = to_date (: P18_DATE_TO, 'DD-MON-YY')
    AND DATE_TO > = to_date (: P18_DATE_FROM, 'DD-MON-YY')

    If it returns no data page will present as usual, if it does not return the data from the confirmation box will appear, and the message will be also the result of a query-driven.

    If the message would be something like...

    Project (s) + "select the NAME OF PROJECTS WHERE ID IN (SELECT PROJ_ID FROM LINKEDPROJECTS WHERE ENV_ID =: P18_ENV_ID +)"
    + AND IDENTIFIANT_COMPOSANT =: P18_COMP_ID +.
    + AND DATE_FROM < = to_date(:P18_DATE_TO, 'DD-MON-YY') +.
    + AND DATE_TO > = to_date (: P18_DATE_FROM, ' MON-JJ-AA "") "+ have this environment for the dates you selected.  Do you want to continue with the reservation?

    By selecting Yes submits the page, select no hands it to the page.

    Had this work now, if it can help someone else out there that's what looked like my javascript in the end...

  • Display of the results of query in Excel on the Web

    Hello

    I try to display data from a query in excel on the web without creating an existing file. I know I can create a CSV using UTL_FILE and post it but I was hoping there was a way to do it without actually creating the file. I have a procedure that resembles

    PROCEDURE displayAsCSV is
    cursor STUD_CURS is
    Select * from students;

    BEGIN
    for STUD_REC loop STUD_CURS
    HTP. Print (' "' |") STUD_REC. FIRST_NAME. » " , " '|| STUD_REC. LAST_NAME. » " ');
    end loop;
    END;

    Anyone know if it is possible to display these results in excel in the browser by altering the MIME types or something similar?

    Thank you

    Check Tom owa_sylk utility with the appropriate mime type.

  • To access the results of query XML MSSQL



    I use MS SQL Server with a query of the form: SELECT * FROM tablename FOR XML AUTO [, XMLDATA]
    (The brackets above to indicate optional use of the XMLDATA option and are not explicit)
    I'm capable of outputting the result in passing the name of the query to CFDUMP so I know that the SQL statement returns the correct information. However, I want to store the XML in a string variable, in the end to go to XMLParse (for example).

    How to access the ResultSet? Columns in the table are not relevant in the case of XML output.

    Nevermind, sorted it.

    For anyone interested, the answer is that the query can be serialized to a string via CFWDDX.

  • Strange ROWNUM result on query complex using separate results

    We have a very complicated query that is a combination of implicit and explicit joins on more than 10 tables in the database. Due to performance issues and timeout if we let him return the entire result set, I'm limiting it to a number using rownum.

    Initially, we were using a "select * of (select distinct * insert here * order of main by id request) where rownum < = 300 ', but work stopped when a new piece of research has been implemented that makes the whole result set then cut accepting up to 300 results for 5 minutes, which is the maximum of our web server can define for a timeout.

    So I tried to change it simply to "select distinct * insert here the main query * and rownum < = 300. This is for a reason any returns only one record. If I add THAT ROWNUM to the list of displayed values it displays 300 lines of exactly the same values with different rownums, who then likely get collapsed down by the distinct in the single record that I see.

    Is there a better way to do it? We can't simply not the complete set of results in a subquery to whittle down, but try to whittle down to the main request gives weird results.

    A better approach would be to improve the performance of the main query. On the one hand, do come back less (or not) duplicate lines would probably improve the performance considerably, because he's back at least 300 copies of certain lines. Making a DIFFERENT one on a large number of lines can be a problem in itself huge performance.

  • Want to Elimate 'SYS. ODCIVARCHAR2LIST"by the result of query

    Hello

    Oracle Version installed is 11.0.2r6. I have a dummy table with data as below:

    STID ADDRESS Type_de_fichier
    -------- ------------------ ----------------
    SALES of ABC 9927 has 0
    TRANSFER of XYZ 9927 b 0
    TRANSFER of ABC 9927 has 0
    TRANSFER of XYZ 9927 b 0

    I want that the output voltage:

    STID ADDRESS Type_de_fichier
    -------- ------------------ ----------------
    9927-0 ABC SALES, TRANSFER
    TRANSFER of XYZ 9927 b 0

    I used 2 methods to achieve the same result, but face some problems.

    Method 1:
    --------------
    SELECT STID, ADDRESS, LISTAGG (File_Type, ',') within THE GROUP (ORDER BY Type_de_fichier) AS file_type
    MODELING
    STID GROUP, ADDRESS;

    I got the output as:

    STID ADDRESS Type_de_fichier
    -------- ------------------ ----------------
    9927-0 ABC SALES, TRANSFER
    9927b 0 XYZ, TRANSFER

    Method 2:
    -------------
    SELECT STID,
    ADDRESS,
    CAST (COLLECT (SEPARATE File_Type) AS SYS. ODCIVARCHAR2LIST) AS File_Type
    FROM (SELECT STID, ADDRESS, MODEL Type_de_fichier)
    STID GROUP, ADDRESS;

    I got the output as:

    STID ADDRESS Type_de_fichier
    -------- ------------------ ----------------
    9927-0 ABC SYS. ODCIVARCHAR2LIST (SALES, TRANSFER)
    9927b 0 XYZ SYS. ODCIVARCHAR2LIST (TRANSFER)

    Same method 2 gave good result which I like, "SYS. ODCIVARCHAR2LIST"is coming as a prefix in the result. I tried to use the replace, but it does not work. I tried to use the "wm_concat" method, but it does not work.

    Can someone help me please to get there? I want a simple Select statement, not the functions/procedures etc.

    Thank you
    Stéphane.

    And what about:

    SELECT STID, ADDRESS, LISTAGG(File_Type, ',') WITHIN GROUP (ORDER BY File_Type) AS file_type
    FROM (
         SELECT DISTINCT STID, ADDRESS, File_Type
         FROM DUMMY
         )
    GROUP BY STID, ADDRESS;
    
  • In the results of query with consecutive Dates

    I have a table like this:

    volume of queue data_date
    01/09/01 2324, 353
    01/09/03 2324, 34
    2324 01/09/04 43
    2325 01/09/01 53
    01/09/02 2325, 66


    I want to have output like this:

    volume of queue data_date
    01/09/01 2324, 353
    * 2324 01/09/02 0 *.
    01/09/03 2324, 34
    2324 01/09/04 43
    2325 01/09/01 53
    01/09/02 2325, 66

    Note the filled in date 01/09/02.

    What I'm doing now is using a function table in select pipeline than iteratates the date of the execution of a statement range for each date and make a current output. A little slow, but faster than the old solution below.

    I also define operations using a single query that contains trade unions and disadvantages. This has proved to be slow.

    The only thing I have not tried is to have a stored proc popuate the value 0 for the missing date.

    Is there another way to do that is effective?

    I use a 10g database, but soon the data will be brought to a 11g.

    Welcome to the forums!

    I would say that one of the best ways on the latest versions of Oracle using the PARTITION OUTER JOIN.

    See the following link for examples/explanation: partition outer join in oracle 10 g

  • Types of return ORA-06504 PL/SQL result set query or variables do not match

    I reproduced with a bunch of proc a simple. How to do this? I tested it using the tool DEVELOPER PL/SQL for oracle. Is the tool the problem?

    create or replace package pkg_test is
    (Test_it) PROCEDURE
    po_cursor OUT NOCOPY sys_refcursor
    )
    ;
    end pkg_test;

    create or replace package body is pkg_test
    PROCEDURE test_it (po_cursor OUT NOCOPY sys_refcursor)
    AS
    PROCEDURE open_out_cursor
    IS
    BEGIN
    OPEN FOR Po_cursor
    SELECT enum, ename FROM employee
    ;
    END open_out_cursor;
    BEGIN
    open_out_cursor;
    END test_it;
    end pkg_test;

    create or replace procedure test_proc
    is
    v_emp_cursor sys_refcursor;
    type t_emp_in is record
    (
    enum employee.enum%TYPE,
    Ename employee.ename%TYPE
    );
    v_emp_rec t_emp_in;
    Start
    pkg_test.test_it (v_emp_cursor);
    LOOP
    extract the v_emp_cursor in v_emp_rec; -Error ORA-06504
    EXIT WHEN v_emp_cursor % NOTFOUND;
    DBMS_OUTPUT. Put_line (' number of emp = ' | v_emp_rec.enum);
    DBMS_OUTPUT. Put_line (' name of emp = ' | v_emp_rec.ename);
    END LOOP;
    close v_emp_cursor;
    end test_proc;

    Jin

    SQL> create or replace package pkg_test is
      2  PROCEDURE test_it (
      3  po_cursor OUT NOCOPY sys_refcursor
      4  )
      5  ;
      6  end pkg_test;
      7  /
    
    Package created.
    
    SQL> create or replace package body pkg_test is
      2  PROCEDURE test_it ( po_cursor OUT NOCOPY sys_refcursor )
      3  AS
      4  PROCEDURE open_out_cursor
      5  IS
      6  BEGIN
      7  OPEN po_cursor FOR
      8  SELECT empno,ename FROM emp
      9  ;
     10  END open_out_cursor;
     11  BEGIN
     12  open_out_cursor;
     13  END test_it;
     14  end pkg_test;
     15  /
    
    Package body created.
    
      1  create or replace procedure test_proc
      2  is
      3  v_emp_cursor sys_refcursor;
      4  type t_emp_in is record
      5  (
      6  enum emp.empno%TYPE,
      7  ename emp.ename%TYPE
      8  );
      9  v_emp_rec t_emp_in;
     10  begin
     11  pkg_test.test_it(v_emp_cursor) ;
     12  LOOP
     13  fetch v_emp_cursor into v_emp_rec.enum,v_emp_rec.ename;
     14  EXIT WHEN v_emp_cursor%NOTFOUND;
     15  DBMS_OUTPUT.PUT_LINE ('emp number = ' || v_emp_rec.enum);
     16  DBMS_OUTPUT.PUT_LINE ('emp name = ' || v_emp_rec.ename);
     17  END LOOP;
     18  close v_emp_cursor;
     19* end test_proc;
    SQL> /
    
    Procedure created.
    

    and you want to learn more about slider REF... :)

    PL/SQL 101: understanding of the Ref Cursor
    PL/SQL 101: Understand the Ref Cursor

    Published by: babaravi on October 10, 2009 09:22

  • How can I integrate my tree using the tree query in combobox

    Hi all

    I have a request of tree and you want to use the same query tree to put a tree inside a ComboBox as combobox category in this link
    http://forums.Oracle.com/forums/search! default.jspa

    Can someone help me to do it... I also use my fine navigation tree.

    With respect,
    Sunil Bhatia

    Hello

    LEVEL is not a real column - it's a nickname, so it shouldn't be on your table, because it generates the SQL.

    Your statement could be something like:

    SELECT LPAD(' ', 2 * (LEVEL-1), '.') || "NAME" d, "PAGE_NO" r
    FROM APEX_PAGES
    WHERE PAGE_NO NOT IN (SELECT "PAGE_NO" FROM "#OWNER#"."APEX_USER_PAGES" WHERE "APP_USER" = :APP_USER)
    START WITH PAGE_NO = 1
    CONNECT BY PRIOR PAGE_NO = PARENT_PAGE_NO
    

    I don't know what would be your starting page number - it would be to the top of the tree - so I just put 1 in this example.

    Here is a page that I put in place using my example of EMP table, just to show what would be the result: [http://apex.oracle.com/pls/otn/f?p=35917:22]

    Andy

  • Limit the number of CMIS query results

    Hello
    Can we limit the number of CMIS query results
    my query is
    SELECT * from ora: t:IDC:GlobalProfile WHERE the ora: p:xRegionDefinition AS \'ALERTRD\'
    I want only newer 2 alerts to display.

    Thank you

    You use the CMIS query in a workflow of presenter content in WebCenter Portal? These documents provide a maxResults parameter to set.

Maybe you are looking for