11G SQL pivot example?

Hello,
Can anyone help me write a SQL pivot statement using 11G to do the following?:
Table columns
=========
Deliverable
Phase (For simplicity we'll make the total possible Phase values equal 1 to 13)
Delv_IN_Phase_Y_N Char(3) values 'Yes' or 'No'
I want to make a matrix with these 3 columns in the above table (in reality a complex view) :
- Deliverable is first column.
- Next 13 column headers display 1 to 13 (the posiible values contained in the 'Phase' column).
- The matrix values under the 'Phase' Column headers are the Yes/No values held in the Delv_in_Phase column.
Deliverable Phase 1 Phase 2 Phase 3 Phase 4 ......... Phase 13
=========================================================
Product Market Plan Yes No No Yes No
Bid Plan No Yes No ...........................................
Contract Summary ................................................................................
Quality Plan .................................................................................
Thanks for any help in advance.
Carol

Just a simple example based on what I could grasp from your table description.
I assume you can't have more than 1 value (either 'yes' or 'no' for a given deliverable in each phase).
Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
Connected as fsitja
SQL> with t as (
  2  select 'Product Market Plan' deliverable, 1 phase, 'NO' Delv_IN_Phase_Y_N from dual union all
  3  select 'Product Market Plan' deliverable, 2 phase, 'YES' Delv_IN_Phase_Y_N from dual union all
  4  select 'Product Market Plan' deliverable, 3 phase, 'YES' Delv_IN_Phase_Y_N from dual union all
  5  select 'Bid Plan', 1, 'YES' from dual union all
  6  select 'Bid Plan', 2, 'NO' from dual union all
  7  select 'Bid Plan', 3, 'NO' from dual union all
  8  select 'Contract Summary', 1, 'NO' from dual union all
  9  select 'Contract Summary', 2, 'NO' from dual union all
10  select 'Contract Summary', 3, 'YES' from dual union all
11  select 'Quality Plan', 1, 'YES' from dual union all
12  select 'Quality Plan', 2, 'YES' from dual union all
13  select 'Quality Plan', 3, 'NO' from dual)
14  -- END OF SAMPLE DATA
15  SELECT *
16    FROM t
17   PIVOT(MAX(delv_in_phase_y_n) FOR phase IN (1 AS phase_1, 2 AS phase_2, 3 AS phase_3))
18  /
DELIVERABLE         PHASE_1 PHASE_2 PHASE_3
Contract Summary    NO      NO      YES
Bid Plan            YES     NO      NO
Product Market Plan NO      YES     YES
Quality Plan        YES     YES     NO
SQL> You can play around and expand the pivot by adding the whole 13 values inside the "FOR phase IN (val1 as column1, etc)" just thought I'd keep it simple.
=> [Documentation Reference here|http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#CHDCEJJE]
Regards.

Similar Messages

  • Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT

    Can we use multiple "pivot_for_clauses" in 11g SQL PIVOT. Below SQL is an example of what I am trying to do - In this case instead of using JOIN, can I have three pivot_for_clauses in the same sql?
    SQL:
    MERGE INTO Test_1 dest
    USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
    FROM (SELECT company_id,action_type_id
    FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
    PIVOT (count(action_type_id) FOR (action_type_id) IN ((1) as num_logins,(2) as num_logouts,(61) as
    num_logins_from_mobile_device,(16) as num_pref_changed,....)) P1
    JOIN
    (SELECT company_id,action_type_id,tx_type_id
    FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
    PIVOT (count(action_type_id) FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice, (4,4) AS
    edit_invoice,(3,3) as num_checks,(3,47) as num_paychecks,(3,7) as num_recvd_payments,(3,9) as num_bills,
    (3,35) as num_estimates,(3,46) as num_purchase_orders)) P2
    on P1.company_id=P2.company_id
    JOIN
    (SELECT company_id,action_type_id,list_type_id
    FROM Testauditinfo_1 where trunc(audit_date_time)=trunc(sysdate)-1) a
    PIVOT (count(action_type_id) FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,(3,1) as
    num_accounts,(3,4) as num_employees,(3,6) as num_customers,(3,14) as num_memorized_reports)) P3
    on P2.company_id=P3.company_id
    left outer JOIN
    (SELECT company_id,create_date,count(*) as num_logos
    FROM qbo.companylogos_1 group by company_id,create_date having trunc(create_date)=trunc(sysdate)-1) P4
    on P3.company_id=P4.company_id
    ORDER BY P1.company_id) source
    ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))WHEN MATCHED THEN
    UPDATE SET dest.num_items = source.num_items where 1=2
    WHEN NOT MATCHED THEN
    INSERT (dest.company_id,.....) values (source.company_id,.....);

    Maybe
    MERGE INTO Test_1 dest
    USING (SELECT P1.company_id,trunc(sysdate) as load_date,num_logins,......
             FROM (select *
                     from (SELECT company_id,action_type_id
                             FROM Testauditinfo_1
                            where trunc(audit_date_time) = trunc(sysdate)-1
                          ) a
                          PIVOT (count(action_type_id)
                            FOR (action_type_id) IN ((1) as num_logins,
                                                     (2) as num_logouts,(61) as num_logins_from_mobile_device,
                                                     (16) as num_pref_changed,....
                  ) P1
                  JOIN
                  (select *
                     from (SELECT company_id,action_type_id,tx_type_id
                             FROM Testauditinfo_1
                            where trunc(audit_date_time) = trunc(sysdate)-1
                          ) a
                          PIVOT (count(action_type_id)
                            FOR (action_type_id,tx_type_id) IN ((3,4) AS add_invoice,
                                                                (4,4) AS edit_invoice,
                                                                (3,3) as num_checks,
                                                                (3,47) as num_paychecks,
                                                                (3,7) as num_recvd_payments,
                                                                (3,9) as num_bills,
                                                                (3,35) as num_estimates,(3,46) as num_purchase_orders
                  ) P2
               on P1.company_id = P2.company_id
                  JOIN
                  (select *
                     from (SELECT company_id,action_type_id,list_type_id
                             FROM Testauditinfo_1
                            where trunc(audit_date_time) = trunc(sysdate)-1
                          ) a
                          PIVOT (count(action_type_id)
                            FOR (action_type_id,list_type_id) IN ((3,2) AS num_items,
                                                                  (3,1) as num_accounts,
                                                                  (3,4) as num_employees,
                                                                  (3,6) as num_customers,
                                                                  (3,14) as num_memorized_reports
                  ) P3
               on P2.company_id = P3.company_id
                  left outer JOIN
                  (SELECT company_id,create_date,count(*) as num_logos
                     FROM qbo.companylogos_1
                    group by company_id,create_date
                    having trunc(create_date) = trunc(sysdate)-1
                  ) P4
               on P3.company_id = P4.company_id
            ORDER BY P1.company_id
          ) source
       ON ((dest.company_id = source.company_id) and (dest.load_date = source.load_date))
    WHEN MATCHED
    THEN UPDATE SET dest.num_items = source.num_items where 1 = 2
    WHEN NOT MATCHED
    THEN INSERT (dest.company_id,.....)
          values (source.company_id,.....)Did you try it ?
    Regards
    Etbin

  • Oracle Database 11g: SQL Fundamentals I 1Z0-051 Question

    i bought the OCA Oracle Database 11g: SQL Fundamentals I Exam Guide (Exam 1Z0-051) and i am not sure do i have to read the whole book ! or just go through the exam objectives table ? because the book covers lots of topics that's not in the exam and i am kind of tight on time if any one had the book or used it pls help
    To make it more clear i have a table in the book that shows each exam topic with page number next to it Like this:
    Restricting and Sorting Data
    [ ]      Limit the rows that are retrieved by a query Pg:104
    [ ]      Sort the rows that are retrieved by a query Pg:136
    [ ]      Use ampersand substitution to restrict and sort output at runtime
    Using Single-Row Functions to Customize Output
    [ ]      Describe various types of functions available in SQL Pg:170
    [ ]      Use character, number, and date functions in SELECT statements Pg:177
    Edited by: user7804566 on 01-Mar-2009 02:00

    Yes indeed. Practice at work (and elsewhere) is the best way to learn and ro reinforce learning.
    However, the more you read, the more you will be exposed to ideas and variations. Eventually you will find that many of the books have errors in various places. You will be winning when you are able to read and identify the errors AND explain why they are errors.
    The way your original question was written implied that you were after the minimum effort to pass an exam. Your last reply implies a different, and better, attitude.
    My suggestion therefore is to concentrate on the actual examples, but as quickly as possible expand to areas of interest. Explore as much as you possibly can, but make it a 'learning exploration' byut asking yourself questions and then investigating what the answer is.
    Also note that in Oracle nearly every answer has an exception. The best of the best know this and try very hard to understand when things go according to plan and when (and why) expections occur.

  • Book: oracle database 11g sql fundamentals i

    dear all,
    i would like to pass the oracle certification in forms application.
    where can i find the ebook (pdf) of the fist course (oracle database 11g sql fundamentals i) in order to study and applying to take the Oracle PL/SQL Developer Certified Associate.
    Tnank you. i ll appreciate your help.

    Hi,
    where can i find the ebook (pdf) of the fist course (oracle database 11g sql fundamentals i) in order to study and applying to take the Oracle PL/SQL Developer Certified AssociateBy attending the class at OU or purchasing the book.
    Thanks,
    Hussein

  • May i go for sql expert(1Z0-047) exam or 11g sql fundamentals 1(1Z0-051)

    Hi all,
    Please suggest me, may i go for sql expert(1Z0-047) Test or 11g sql fundamentals 1(1Z0-051) Test with
    oracle Administration 1(1Z0-042) Test.
    Which will be the best option.
    Thanks & Regards

    You may use either exam along with the Oracle Administration 1 (1Z0-042) exam if your goal is to get a 10g DBA OCA credential.
    The SQL Expert exam is quite a bit more challenging than the SQL Fundamentals exam. On the other hand, the SQL Expert exam gives you a separate SQL Certified Expert credential. If you can pass it, you should take the SQL Expert exam.
    Justin

  • UTL_FILE - PL/SQL Package Example

    Does anyone has UTL_FILE - PL/SQL Package Example.
    ( Which will read the file and insert into table )
    Thanks
    SK
    Message was edited by:
    ksridhar69

    If you just need to read the contents and insert into the table, check out External tables

  • 1z0-051 Oracle Database 11g SQL Fundamentals 1 exam DUMPS

    Hi dear associates.
    can you please help me 1z0-051 Oracle Database 11g SQL Fundamentals 1 exam dumps for preparation sql fundamental exam......!

    https://blogs.oracle.com/certification/entry/0477
    https://blogs.oracle.com/certification/entry/the_route_you_choose
    If you sincerely expect to get certified via legitimate means, pl edit your post to remove words with negative connotations
    HTH
    Srini

  • Do i have to pay exam center fee to an authorized oracle exam center(new horizon) in Bangladesh rather than the exam fee of Oracle Database 11g: SQL Fundamentals I ?

    Do i have to pay exam center fee to an authorized oracle exam center(new horizon) in Bangladesh rather than the exam fee of Oracle Database 11g: SQL Fundamentals I ?

    I agree with Matthew that I cannot be sure exactly what you are asking.
    Generally i regard it as less risk to yourself to schedule and pay Pearson Vue directly.
    However if you contact the exam center and get them to schedule for you my understanding is you pay them. Unfortunately there is risk of the exam center overcharging you (99%++ of most most worldwide wont).
    The only reasons for doing this I can think of is (there may be more) :-
    - is if you do not have credit/debit cards that Pearson Vue would accept.
    - The center will accept turn up and schedule and your transport to the exam center might be unreliable and you are worried you might miss the appointment and you are hoping to pay on arrival (some will not accept this).

  • PIVOT example

    I need to some help to PIVOT my dataset, need to move the description column to individual columns, so I have 1 row for eaach id
    below is an example
    declare @Pivot table (
    S_dates datetime
    , id varchar(10)
    , code varchar(100)
    , description varchar(max))
    insert @Pivot select '2014-03-24 00:00:00.000','1580/7','07611819360532','Matrix 90° L-Plate, medium, 2+2 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert @Pivot select '2014-03-24 00:00:00.000','1580/7','07611819362369','Matrix Screw Ø 1.85 mm, self-drilling, length 4 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-24 00:00:00.000','1580/7','07611819362383','Matrix Screw Ø 1.85 mm, self-drilling, length 5 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-24 00:00:00.000','1580/7','07611819362437','Matrix Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','7551/4','07611819362406','Matrix Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','7551/4','07611819362437','Matrix Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','7551/4','07611819377523','Matrix Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','4820/4','07611819360709','Matrix Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','4820/4','07611819362222','Matrix Screw Ø 1.85 mm, self-tapping, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','4820/4','07611819377523','Matrix Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','3738/4','07611819360709','Matrix Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','3738/4','07611819362222','Matrix Screw Ø 1.85 mm, self-tapping, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','3738/4','07611819362406','Matrix Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','3738/4','07611819362437','Matrix Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert @Pivot select '2014-03-21 00:00:00.000','3738/4','07611819377523','Matrix Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','6578/1','07611819360709','Matrix Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert @Pivot select '2014-03-21 00:00:00.000','6578/1','07611819362406','Matrix Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert @Pivot select '2014-03-12 00:00:00.000','7666/1','07611819381100','Drill Bit Ø 1.5 mm with Stop, length 50/6 mm, 2-flute, for J-Latch Coupling, sterile'
    select * from @Pivot

    Hi,
    Please see the Query below hope it helps. Its dynamic with data. I have used Temp Tables instead of table variables. Hope its helps.
    Create
    table #Pivot (
          S_dates
    datetime
    , id varchar(10)
    , code varchar(100)
    , description
    varchar(max))
    insert #Pivot
    select '2014-03-24 00:00:00.000','1580/7','07611819360532','Matrix
    90° L-Plate, medium, 2+2 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert #Pivot
    select '2014-03-24 00:00:00.000','1580/7','07611819362369','Matrix
    Screw Ø 1.85 mm, self-drilling, length 4 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-24 00:00:00.000','1580/7','07611819362383','Matrix
    Screw Ø 1.85 mm, self-drilling, length 5 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-24 00:00:00.000','1580/7','07611819362437','Matrix
    Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','7551/4','07611819362406','Matrix
    Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','7551/4','07611819362437','Matrix
    Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','7551/4','07611819377523','Matrix
    Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','4820/4','07611819360709','Matrix
    Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','4820/4','07611819362222','Matrix
    Screw Ø 1.85 mm, self-tapping, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','4820/4','07611819377523','Matrix
    Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','3738/4','07611819360709','Matrix
    Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','3738/4','07611819362222','Matrix
    Screw Ø 1.85 mm, self-tapping, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','3738/4','07611819362406','Matrix
    Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','3738/4','07611819362437','Matrix
    Screw Ø 2.1 mm, self-tapping, length 4 mm, Titanium Alloy (TAN), sterile, pack of 1 unit in Clip'
    insert #Pivot
    select '2014-03-21 00:00:00.000','3738/4','07611819377523','Matrix
    Drill Bit Ø 1.4 mm with Stop, length 44.5/8 mm, for J-Latch Coupling, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','6578/1','07611819360709','Matrix
    Anatomic L-Plate, short, 3+3 holes, reversible, thickness 0.8 mm, Pure Titanium, sterile'
    insert #Pivot
    select '2014-03-21 00:00:00.000','6578/1','07611819362406','Matrix
    Screw Ø 1.85 mm, self-drilling, length 6 mm, Titanium Alloy (TAN), sterile, pack of 4 units in Clip'
    insert #Pivot
    select '2014-03-12 00:00:00.000','7666/1','07611819381100','Drill
    Bit Ø 1.5 mm with Stop, length 50/6 mm, 2-flute, for J-Latch Coupling, sterile'
    select
    * from #Pivot
    Declare @SQL 
    Varchar(max)
    ,  @Var  
    Varchar(max)
    SELECT
            @Var=coalesce(@Var+',','')+'['
    + code +']'
    FROM
    (Select
    DISTINCT code from #Pivot)
    as A
    Select @Var
    SET @SQL
    = ''
    SET @SQL
    = '
    SELECT id, S_dates,'
    +
    @Var
    +'
    FROM
    (SELECT *
        FROM #Pivot) AS SourceTable PIVOT
    MAX(description)
    FOR Code IN ('+ @Var
    + ')
    ) AS PivotTable;'
    Exec
    (@SQL)
    Regards, PS

  • SQL Pivot Query

    Hi Experts
    I recently purchased a copy of Gordon's book to help me create a pivot query based on the examples at the end which I hope to show me a set of data based on my Sales Order tables.   Unfortunately I have found it a little too complex.
    In my ORDR table I have 10 UDFs which relate to various statuses and dates in the sales order process. 
    What I would like is to see a pivot table query of the sum quanties of items at the different stages (as rows) against the dates in weeks.
    In the rows would be the status UDF fields:
    U_DES_STAGE
    U_PRN_STAGE
    U_PRS_STAGE
    U_SEW_STAGE
    U_EMB_STAGE
    for each UDF there is an associated date UDF
    U_DES_STAGE_DATE
    U_PRN_STAGE_DATE
    U_PRS_STAGE_DATE
    U_SEW_STAGE_DATE
    U_EMB_STAGE_DATE
    The columns I require in the pivot table would be the UDF stage dates which are always input for the week ending Friday.
    The data in the pivot should be the sum of the quantities in the sales orders rows RDR1.
    Stage
    W/E 14/3/2014
    W/E 21/3/2014
    W/E 28/3/2014
    W/E 4/4/2014
    W/E 11/4/2014
    W/E 18/4/2014
    DES
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    PRN
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    PRS
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    SEW
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    EMB
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    Sum of Qty
    The problem is that I am not sure as to how to add the WHERE clause to limit the results to only the 5 items (DES% or PRN% or PRS% or SEW% or EMB%)
    I would be very grateful for any assistance.
    Regards
    Geoff

    Hi Gordon - you're very welcome.   The content of the book is very helpful to an SQL novice!
    Essentially the 10 UDF are for recording each stage of the processes involved in the sales order.    there are 5 processes so each process has 2 fields - one records the initals of the staff member who is responsible and the other records the date the process is scheduled for.
    We want to be able to produce a schedule to show us how many garments are scheduled on a sales order in a particular week effectively turning this table into the one below it:
    Document Number
    Quantity
    Design - Scheduled Date
    Dye Print Scheduled Date
    Dye Press Scheduled Date
    Dye Sewing Scheduled Date
    Embroidery - Scheduled Date
    Print – Scheduled Date
    298835
    315
    12.07.10
    06.09.10
    300058
    144
    22.07.10
    06.09.10
    300921
    29
    01.10.10
    302330
    15
    30.09.10
    30.09.10
    302820
    460
    05.10.10
    302833
    55
    20.09.10
    22.09.10
    303476
    86
    06.10.10
    06.10.10
    303948
    13
    11.08.10
    11.08.10
    303982
    106
    26.10.10
    27.10.10
    304012
    99
    25.11.10
    25.11.10
    304186
    6
    27.08.10
    27.08.10
    304331
    10
    07.09.10
    07.09.10
    304382
    16
    29.09.10
    29.09.10
    304399
    15
    19.08.10
    304556
    85
    01.10.10
    22.10.10
    304557
    11
    29.09.10
    29.09.10
    304563
    8
    29.09.10
    29.09.10
    304567
    7
    29.09.10
    304570
    19
    01.10.10
    22.10.10
    304571
    113
    01.10.10
    22.10.10
    304576
    11
    29.09.10
    29.09.10
    304603
    72
    22.09.10
    23.09.10
    304604
    86
    22.09.10
    23.09.10
    304606
    107
    22.09.10
    23.09.10
    304608
    107
    22.09.10
    23.09.10
    304613
    107
    22.09.10
    23.09.10
    304693
    12
    29.09.10
    29.09.10
    304710
    5
    29.09.10
    304760
    6
    29.09.10
    29.09.10
    304765
    4
    29.09.10
    304899
    42
    15.09.10
    304963
    100
    22.09.10
    24.09.10
    304974
    719
    27.09.10
    29.09.10
    304975
    401
    28.09.10
    29.09.10

  • Dynamic SQL Pivoting(Converting Row to Columns)

    Hi All,
    I am using Oracle 9i (Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production)
    and also 10g version
    I am facing difficulties to find out the logic for
    converting the set of values in one of the columns into the column headings for the entire query.
    create TABLE my_tab ( deptno VARCHAR2(5), job VARCHAR2(50), sal NUMBER);
    insert into my_tab ( deptno,JOB, sal) values ( 10, 'ANALYST', 23000);
    insert into my_tab ( deptno,JOB, sal) values ( 10, 'SALESMAN', 1500);
    insert into my_tab ( deptno,JOB, sal) values ( 10, 'CLERK', 3550);
    insert into my_tab ( deptno,JOB, sal) values ( 20, 'SALESMAN', 700);
    insert into my_tab ( deptno,JOB, sal) values ( 20, 'ANALYST', 4200);
    insert into my_tab ( deptno,JOB, sal) values ( 30, 'SALESMAN', 5600);
    insert into my_tab ( deptno,JOB, sal) values ( 30, 'CLERK', 12000);
    insert into my_tab ( deptno,JOB, sal) values ( 30, 'ANALYST', 19000);
    COMMIT;
    SELECT * FROM my_tab
    DEPTNO ______ JOB ________ SAL
    10 ______ ANALYST ________ 23000
    10 ______ SALESMAN     ________     1500
    10     _______ CLERK     ________     3550
    20     _______     SALESMAN ________     700
    20     _______     ANALYST     ________ 4200
    30     _______     SALESMAN ________     5600
    30     _______     CLERK     _______          12000
    30     _______ ANALYST     _______     19000
    --And I wish to convert it into this structure:
    DEPTNO ________ ANALYST ________ SALESMAN _________ CLERK
    10      ________     23000 ________     1500     _________     3550
    20     ________ 4200 ________     700     _________     NULL
    30     ________ 19000 ________     5600     _________     12000
    It may be dynamic. i.e Later i inserted more two records into My_tab.
    insert into my_tab ( deptno,JOB, sal) values ( 20, 'CLERK', 3400);
    insert into my_tab ( deptno,JOB, sal) values ( 30, 'MANAGER', 48000);
    So it should be dynamic.
    output is like this.
    DEPTNO ________ ANALYST ______ SALESMAN ______ CLERK ______ MANAMGER
    10           ________ 23000     ______ 1500     ______ 3550     ______     NULL
    20          ________ 4200     ______ 700     ______ 3400     ______     NULL
    30          ________ 19000     ______ 5600     ______ 12000     ______     48000
    Please help me regarding this.
    With warm regards,
    Prasanta

    Hi, Prasanta,
    Displaying one column from many rows as many columns on one row is called Pivoting . The following thread shows the basics of how to pivot:
    Help for a query to add columns
    That example uses the aggregate COUNT function; you'll want SUM (or possibly MIN or MAX) instead.
    Getting a dynamic number of columns requires Dynamic SQL . As a simpler alternative to pivoting and dynamic SQL, you might consider String Aggregation , where you concatenate a column from many rows into one big string, to be displayed on one row.
    See the following thread for more about string aggregation and other options on pivoting into a variable number of columns:
    Re: Report count and sum from many rows into many columns

  • 11g sql performance analyzer

    dear all,
    i am trying to use 11g new feature sql perfomance analyzer SPA to check the result of changing intialization parameter on certain sql tuning set , the problem is the enterprize manager gives me list of 106 parameter to choose one of them , which is the isses_modifiable parameters,
    my questions is can i use this feature to check the result of changing one of parameters out of this scope (db_block_size) for example,
    thanks for reading

    This is a duplicate.
    Please be courteous to others and only post your question one time and in the appropriate forum.
    Thank you.

  • Dynamic SQL PIVOT not producing output?

    Hey all,
    Find my source code with test data scripts below. Since my production system is not connected to the inet, I had to type this
    "by hand" as it were, so please pardon any mispellings. I have no way to test on my inet-enabled PC before posting.
    Anyways, here's my issue: if you run the below code as PL/SQL script, it runs fine but it produces NO output (it should display a
    grid of data). That is my dilemma. How to get my dynamic pivot to actually SHOW the data. So I've been experimenting with
    EXECUTE IMMEDIATE, but when I use that syntax, it blows up with the error:
    PLS-00321: expression 'TMPTABLE' is inappropriate as the left hand side of an assignment statement
    I have provide the lines below which cause the error, but they are commented out so you can see it runs fine the 1st way (yet
    displays no data) and blows up the 2nd way. I would appreciate your insights.
    Thanks
    DROP TABLE table1;
    DROP TABLE table2;
    DROP TABLE datetable;
    CREATE TABLE table1
         TIME_STAMP TIMESTAMP(6) DEFAULT systimestamp NOT NULL,
         Id VARCHAR2(50 BYTE)  NOT NULL
    CREATE TABLE table2
         NAME VARCHAR2(50 BYTE),
         Id VARCHAR2(50 BYTE) NOT NULL
    CREATE TABLE datetable
         YEAR_WEEK VARCHAR2(7 BYTE),
         WEEK_START_DATE DATE
    INSERT INTO table1 VALUES (to_date(‘05/30/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (to_date(‘05/31/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (to_date(‘06/01/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (to_date(‘06/02/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (to_date(‘06/03/2011’,’MM/DD/YYYY’),’2’);
    INSERT INTO table1 VALUES (to_date(‘06/04/2011’,’MM/DD/YYYY’),’2’);
    INSERT INTO table1 VALUES (to_date(‘06/05/2011’,’MM/DD/YYYY’),’2’);
    INSERT INTO table1 VALUES (to_date(‘06/07/2011’,’MM/DD/YYYY’),’2’);
    INSERT INTO table1 VALUES (to_date(‘06/08/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (to_date(‘06/09/2011’,’MM/DD/YYYY’),’1’);
    INSERT INTO table1 VALUES (‘Bob’,’1’);
    INSERT INTO table1 VALUES (‘Gary’,’2’);
    INSERT INTO table1 VALUES (‘2011-21’,to_date(‘05/23/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-22’,to_date(‘05/30/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-23’,to_date(‘06/06/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-24’,to_date(‘06/13/2011’,’MM/DD/YYYY’));
    DECLARE
         sql_txt VARCHAR2 (32767);
         --keep the below commented for the 1st test, uncomment for 2nd test
         --TYPE tmpTable IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
    BEGIN
         sql_txt :=
    Q'{WITH got_dates AS
    SELECT b.name,
    COUNT(*) AS Responded,
    iso.week_start_date AS week_start_date
    FROM
    table1 a INNER JOIN table2 b ON
    (a.id = b.id) INNER JOIN datetable iso ON
    ((case when to_char(a.time_stamp, 'IW')='53' then to_char(cast(to_char(a.time_stamp, 'IYYY') as int)+1) || '-01' else to_char(a.time_stamp, 'IYYY-IW') end) = iso.year_week)
    WHERE
    (a.time_stamp >= sysdate-30)
    GROUP BY
    iso.week_start_date,
    b.name
    SELECT   *
    FROM       got_dates
    PIVOT      (
    SUM (Responded) FOR week_start_date IN (
         FOR d_rec IN     (
    WITH    possible_dates      AS
         SELECT  SYSDATE + 1 - LEVEL     AS time_stamp
         FROM     DUAL
         CONNECT BY     LEVEL <= 31
    SELECT     DISTINCT  'DATE '''
                || TO_CHAR ( c.week_start_date
                              , 'YYYY-MM-DD'
                || ''' AS '
                || TO_CHAR ( c.week_start_date
                              , 'mon_dd_yyyy'
                || CASE          
                           WHEN  DENSE_RANK () OVER (ORDER BY  c.week_start_date) > 1
                    THEN  ','
                   END          AS txt
    FROM          possible_dates     p
    INNER JOIN     datetable      c  ON   c.year_week =
    CASE
    WHEN  TO_CHAR ( p.time_stamp, 'IW') = '53'
    THEN  TO_CHAR (cast(TO_CHAR(p.time_stamp,'IYYY') AS int)+1) || '-01'
    ELSE  TO_CHAR ( p.time_stamp, 'IYYY-IW')
    END
    ORDER BY  txt     DESC
         LOOP
              sql_txt := sql_txt || ' ' || d_rec.txt;
         END LOOP;
         sql_txt := sql_txt || ') )';
    --keep the below commented for the 1st test, uncomment for 2nd test. also, comment out the 2nd EXECUTE IMMEDIATE (only 1 at a time should be uncommented)
    --EXECUTE IMMEDIATE sql_txt BULK COLLECT INTO tmpTable;
    EXECUTE IMMEDIATE sql_txt;
    END;Edited by: user8825851 on Oct 6, 2011 2:12 PM

    Hi,
    user8825851 wrote:
    Find my source code with test data scripts below. Since my production system is not connected to the inet, I had to type this
    "by hand" as it were, so please pardon any mispellings. I have no way to test on my inet-enabled PC before posting. Install an Oracle database on your PC. It's free and it's not difficult. if you're going to use this forum, whatever time you have to invest in it will pay off within a week.
    http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html
    Anyways, here's my issue: if you run the below code as PL/SQL script, it runs fine but it produces NO output (it should display a
    grid of data)...In PL/SQL, you always have to SELECT into something.
    One simple way is to open a cursor. Before running the PL/SQL code, declare a bind variable for the cursor:
    VARIABLE     c     REFCURSOR
    -- And while you're at it, do this, too
    SET  SERVEROUTPUT  ONIn the PL/SQL code, use an OPEN statement in place of EXECUTE IMMEDIATE:
    ...     dbms_output.put_line (sql_txt); -- For debugging only
    --     EXECUTE IMMEDIATE sql_txt;     -- Don't do this
         OPEN :c FOR sql_txt;          -- Do this instead
    END;
    /After the PL/SQL is finsihed, you can use PRINT to see the results:
    PRINT :cIn this case, you'll get an error message because the dynamic code is incorrect. That's what the call to put_line is for: to show exactly what you're running. If there's a problem, you can examine the output, or copy it into a script, edit it and debug it.
    In this case, you'll see that the dynamic SQL ends with:
    PIVOT    (
    SUM (Responded) FOR week_start_date IN (
    ) )The part that's supposed to be dynamic is missing. That part is supposed to be written inside the d_rec cursor loop, but d_rec is returning no rows. That's because of the join condition:
    INNER JOIN     datetable      c  ON   c.year_week =
    CASE
    WHEN  TO_CHAR ( p.time_stamp, 'IW') = '53'
    THEN  TO_CHAR (cast(TO_CHAR(p.time_stamp,'IYYY') AS int)+1) || '-01'
    ELSE  TO_CHAR ( p.time_stamp, 'IYYY-IW')
    END With the given sample data, p.time_stamp is producing values between '2011-36' and '2011-40', but the values in c.week are
    INSERT INTO table1 VALUES (‘2011-21’,to_date(‘05/23/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-22’,to_date(‘05/30/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-23’,to_date(‘06/06/2011’,’MM/DD/YYYY’));
    INSERT INTO table1 VALUES (‘2011-24’,to_date(‘06/13/2011’,’MM/DD/YYYY’));(I assume you meant "INSERT INTO *datetable* " above.)
    Perhaps you meant LEFT OUTER JOIN instead of INNER JOIN in d_rec.

  • 11g SQL query syntax/results differ from 10g

    Hello,
    A bit of an odd situation.  We have a report in 10g that is working as expected and when we run the same report in 11g we slightly different results.  The same physical tables and columns are being used between each report and the number of records (17) returned to OBI are the same.  Both queries are pulling from the same database with the same user id.  As there are differences in how 10g runs queries vs 11g, are there any odd behaviors that I should keep an eye out for in how 11g assembles the data that's returned from the db prior to presenting it on the Analysis?  
    10g Results (correct):
    Region...............Actuals (Prior Qtr).....Up...........Plan Amount....................% of Plan
    AP...........................10,489..............8,965..............................................................
    Americas................114,208...........110,779..................6...........................1969411% 
    EMEA.....................26,799..............23,976..............................................................
    UNASSIGNED....................................................149,957...........................0%
    Grand Total.............151,496...........143,721..........149,962.........................96%
    11g Results (incorrect):
    Region...............Actuals (Prior Qtr).....Up...........Plan Amount....................% of Plan
    AP...........................10,180..............8,965............................................................
    Americas.................90,878...........110,779............................................................ 
    EMEA.....................24,978.............23,976............................................................
    UNASSIGNED....................................................149,957...........................0%
    Grand Total.............126,037..........143,721..........149,957.........................96%
    Thank you!
    Mike
    -------------------- 10g query--------------------------
    -------------------- Sending query to database named EBS Rapid Data Store (id: <<5087545>>):
    WITH
    SAWITH0 AS (select T28761.PERIOD_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH1 AS (select Case when case SAWITH0.c5 when 1 then SAWITH0.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH0.c5 when 1 then SAWITH0.c3 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH0.c2 as c2,
         SAWITH0.c4 as c3
    from
         SAWITH0),
    SAWITH2 AS (select min(SAWITH1.c1) over (partition by SAWITH1.c3)  as c1,
         SAWITH1.c2 as c2
    from
         SAWITH1),
    SAWITH3 AS (select distinct SAWITH2.c1 + 1 as c1,
         SAWITH2.c2 as c2
    from
         SAWITH2),
    SAWITH4 AS (select T28761.QUARTER_RANK as c2,
         T28761.QUARTER_YEAR_NAME as c3,
         T28761.PERIOD_START_DATE as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH5 AS (select Case when case SAWITH4.c5 when 1 then SAWITH4.c4 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH4.c5 when 1 then SAWITH4.c4 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH4.c2 as c2,
         SAWITH4.c3 as c3
    from
         SAWITH4),
    SAWITH6 AS (select distinct min(SAWITH5.c1) over (partition by SAWITH5.c2)  as c1,
         SAWITH5.c2 as c2,
         SAWITH5.c3 as c3
    from
         SAWITH5),
    SAWITH7 AS (select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6
    from
         (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
                   SAWITH6.c3 as c2,
                   T41894.ICN_GROUP as c3,
                   SAWITH6.c2 as c4,
                   T41894.ICN_GROUP_CODE as c5,
                   T30728.PARENT_REGION as c6,
                   ROW_NUMBER() OVER (PARTITION BY T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, SAWITH6.c2 ORDER BY T30728.PARENT_REGION ASC, T41894.ICN_GROUP_CODE ASC, SAWITH6.c2 ASC) as c7
              from
                   SAWITH3 left outer join (
                                  XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
                                  XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
                             XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T37838.OVERRIDE_ICN = T41894.ICN_CODE) On SAWITH3.c2 = T37838.PERIOD_NAME,
                   SAWITH6
              where  ( SAWITH6.c1 = SAWITH3.c1 and SAWITH6.c3 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
              group by T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP, SAWITH6.c2, SAWITH6.c3
         ) D1
    where  ( D1.c7 = 1 ) ),
    SAWITH8 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
         sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2,
         T30728.PARENT_REGION as c3,
         T28761.QUARTER_YEAR_NAME as c6,
         T41894.ICN_GROUP as c7,
         T28761.QUARTER_RANK as c8,
         T41894.ICN_GROUP_CODE as c9
    from
                        XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
                        XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T37838.PERIOD_NAME) left outer join
                   XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
              XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T37838.OVERRIDE_ICN = T41894.ICN_CODE
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
    group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
    SAWITH9 AS (select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6,
         D1.c7 as c7,
         D1.c8 as c8,
         D1.c9 as c9
    from
         (select sum(SAWITH8.c1) over (partition by SAWITH8.c3)  as c1,
                   sum(SAWITH8.c2) over (partition by SAWITH8.c3)  as c2,
                   SAWITH8.c3 as c3,
                   sum(SAWITH8.c1) over (partition by SAWITH8.c8, SAWITH8.c9, SAWITH8.c3)  as c4,
                   sum(SAWITH8.c2) over (partition by SAWITH8.c8, SAWITH8.c9, SAWITH8.c3)  as c5,
                   SAWITH8.c6 as c6,
                   SAWITH8.c7 as c7,
                   SAWITH8.c8 as c8,
                   SAWITH8.c9 as c9,
                   ROW_NUMBER() OVER (PARTITION BY SAWITH8.c3, SAWITH8.c8, SAWITH8.c9 ORDER BY SAWITH8.c3 ASC, SAWITH8.c8 ASC, SAWITH8.c9 ASC) as c10
              from
                   SAWITH8
         ) D1
    where  ( D1.c10 = 1 ) ),
    SAWITH10 AS (select sum(T34877.AMOUNT) as c1,
         T28761.QUARTER_YEAR_NAME as c3,
         T30728.PARENT_REGION as c4,
         T41894.ICN_GROUP as c5,
         T28761.QUARTER_RANK as c6,
         T41894.ICN_GROUP_CODE as c7
    from
                        XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */  left outer join
                        XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T34877.PERIOD_NAME) left outer join
                   XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T34877.SHIP_TO_COUNTRY_CODE2) left outer join
              XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T34877.OVERRIDE_ICN = T41894.ICN_CODE
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' )
    group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
    SAWITH11 AS (select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6,
         D1.c7 as c7
    from
         (select sum(SAWITH10.c1) over (partition by SAWITH10.c4)  as c1,
                   sum(SAWITH10.c1) over (partition by SAWITH10.c6, SAWITH10.c7, SAWITH10.c4)  as c2,
                   SAWITH10.c3 as c3,
                   SAWITH10.c4 as c4,
                   SAWITH10.c5 as c5,
                   SAWITH10.c6 as c6,
                   SAWITH10.c7 as c7,
                   ROW_NUMBER() OVER (PARTITION BY SAWITH10.c4, SAWITH10.c6, SAWITH10.c7 ORDER BY SAWITH10.c4 ASC, SAWITH10.c6 ASC, SAWITH10.c7 ASC) as c8
              from
                   SAWITH10
         ) D1
    where  ( D1.c8 = 1 ) ),
    SAWITH12 AS (select T28761.PERIOD_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH13 AS (select Case when case SAWITH12.c5 when 1 then SAWITH12.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH12.c5 when 1 then SAWITH12.c3 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH12.c2 as c2,
         SAWITH12.c4 as c3
    from
         SAWITH12),
    SAWITH14 AS (select min(SAWITH13.c1) over (partition by SAWITH13.c3)  as c1,
         SAWITH13.c2 as c2
    from
         SAWITH13),
    SAWITH15 AS (select distinct SAWITH14.c1 + 1 as c1,
         SAWITH14.c2 as c2
    from
         SAWITH14),
    SAWITH16 AS (select T28761.QUARTER_YEAR_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH17 AS (select Case when case SAWITH16.c5 when 1 then SAWITH16.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH16.c5 when 1 then SAWITH16.c3 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH16.c2 as c2,
         SAWITH16.c4 as c3
    from
         SAWITH16),
    SAWITH18 AS (select distinct min(SAWITH17.c1) over (partition by SAWITH17.c3)  as c1,
         SAWITH17.c2 as c2
    from
         SAWITH17),
    SAWITH19 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
         T30728.PARENT_REGION as c2
    from
         SAWITH15 left outer join (
                   XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
                   XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) On SAWITH15.c2 = T37838.PERIOD_NAME,
         SAWITH18
    where  ( SAWITH18.c1 = SAWITH15.c1 and SAWITH18.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
    group by T30728.PARENT_REGION),
    SAWITH20 AS (select T28761.PERIOD_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH21 AS (select Case when case SAWITH20.c5 when 1 then SAWITH20.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH20.c5 when 1 then SAWITH20.c3 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH20.c2 as c2,
         SAWITH20.c4 as c3
    from
         SAWITH20),
    SAWITH22 AS (select min(SAWITH21.c1) over (partition by SAWITH21.c3)  as c1,
         SAWITH21.c2 as c2
    from
         SAWITH21),
    SAWITH23 AS (select distinct SAWITH22.c1 + 1 as c1,
         SAWITH22.c2 as c2
    from
         SAWITH22),
    SAWITH24 AS (select T28761.QUARTER_YEAR_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH25 AS (select Case when case SAWITH24.c5 when 1 then SAWITH24.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case SAWITH24.c5 when 1 then SAWITH24.c3 else NULL end  ASC NULLS LAST ) end as c1,
         SAWITH24.c2 as c2,
         SAWITH24.c4 as c3
    from
         SAWITH24),
    SAWITH26 AS (select distinct min(SAWITH25.c1) over (partition by SAWITH25.c3)  as c1,
         SAWITH25.c2 as c2
    from
         SAWITH25),
    SAWITH27 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1
    from
         SAWITH23 left outer join XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  On SAWITH23.c2 = T37838.PERIOD_NAME,
         SAWITH26
    where  ( SAWITH26.c1 = SAWITH23.c1 and SAWITH26.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') ) ),
    SAWITH28 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
         sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2
    from
              XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
              XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T37838.PERIOD_NAME
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') ) ),
    SAWITH29 AS (select sum(T34877.AMOUNT) as c1
    from
              XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */  left outer join
              XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T34877.PERIOD_NAME
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' ) )
    select case  when SAWITH7.c2 is not null then SAWITH7.c2 when SAWITH9.c6 is not null then SAWITH9.c6 when SAWITH11.c3 is not null then SAWITH11.c3 end  as c1,
         case  when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH19.c2 is not null then SAWITH19.c2 when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH11.c4 is not null then SAWITH11.c4 end  as c2,
         case  when SAWITH7.c3 is not null then SAWITH7.c3 when SAWITH9.c7 is not null then SAWITH9.c7 when SAWITH11.c5 is not null then SAWITH11.c5 end  as c3,
         SAWITH9.c5 / nullif( 1000, 0) as c4,
         SAWITH7.c1 / nullif( 1000, 0) as c5,
         SAWITH11.c2 / nullif( 1000, 0) as c6,
         nvl(SAWITH9.c4 , 0) / nullif( nvl(SAWITH11.c2 , 0), 0) * 100 as c7,
         case  when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 when SAWITH11.c6 is not null then SAWITH11.c6 end  as c16,
         case  when SAWITH11.c7 is not null then SAWITH11.c7 when SAWITH9.c9 is not null then SAWITH9.c9 when SAWITH7.c5 is not null then SAWITH7.c5 end  as c17,
         SAWITH27.c1 as c19,
         SAWITH28.c2 as c20,
         SAWITH29.c1 as c21,
         SAWITH28.c1 as c22,
         SAWITH19.c1 as c23,
         SAWITH9.c2 as c24,
         SAWITH11.c1 as c25,
         SAWITH9.c1 as c26
    from
                   SAWITH7 full outer join SAWITH9 On SAWITH7.c5 = SAWITH9.c9 and nvl(SAWITH7.c4 , 88.0) = nvl(SAWITH9.c8 , 88.0) and nvl(SAWITH7.c4 , 99.0) = nvl(SAWITH9.c8 , 99.0) and nvl(SAWITH7.c6 , 'q') = nvl(SAWITH9.c3 , 'q') and nvl(SAWITH7.c6 , 'z') = nvl(SAWITH9.c3 , 'z')) full outer join SAWITH11 On SAWITH11.c7 = case  when SAWITH7.c5 is not null then SAWITH7.c5 when SAWITH9.c9 is not null then SAWITH9.c9 end  and nvl(SAWITH11.c4 , 'q') = nvl(case  when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 end  , 'q') and nvl(SAWITH11.c4 , 'z') = nvl(case  when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 end  , 'z') and nvl(SAWITH11.c6 , 88.0) = nvl(case  when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 end  , 88.0) and nvl(SAWITH11.c6 , 99.0) = nvl(case  when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 end  , 99.0)) full outer join SAWITH19 On nvl(SAWITH19.c2 , 'q') = nvl(case  when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH11.c4 is not null then SAWITH11.c4 end  , 'q') and nvl(SAWITH19.c2 , 'z') = nvl(case  when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH11.c4 is not null then SAWITH11.c4 end  , 'z'),
         SAWITH27,
         SAWITH28,
         SAWITH29
    order by c2
    +++:cfa20000:cfa20015:----2013/08/14 10:31:12
    -------------------- Query Status: Successful Completion
    +++:cfa20000:cfa20015:----2013/08/14 10:31:12
    -------------------- Rows 21, bytes 34272 retrieved from database query id: <<5087545>>
    +++:cfa20000:cfa20015:----2013/08/14 10:31:12
    -------------------- Physical query response time 27 (seconds), id <<5087545>>
    +++:cfa20000:cfa20015:----2013/08/14 10:31:12
    -------------------- Physical Query Summary Stats: Number of physical queries 1, Cumulative time 27, DB-connect time 0 (seconds)
    +++:cfa20000:cfa20015:----2013/08/14 10:31:12
    -------------------- Rows returned to Client 17
    ---------------------------------------------  11g Query ----------------------------------------------------------
    Sending query to database named EBS Rapid Data Store (id: <<2779207>>), connection pool named EBS XXFI Connection Pool, logical request hash 1334563, physical request hash 292e1532: [[
    WITH
    OBICOMMON0 AS (select T28761.PERIOD_NAME as c2,
         T28761.PERIOD_START_DATE as c3,
         T28761.QUARTER_RANK as c4,
         ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5,
         T28761.QUARTER_YEAR_NAME as c6
    from
         XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
    SAWITH0 AS (select Case when case D1.c5 when 1 then D1.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case D1.c5 when 1 then D1.c3 else NULL end  ASC NULLS LAST ) end as c1,
         D1.c2 as c2,
         D1.c4 as c3
    from
         OBICOMMON0 D1),
    SAWITH1 AS (select min(D1.c1) over (partition by D1.c3)  as c1,
         D1.c2 as c2
    from
         SAWITH0 D1),
    SAWITH2 AS (select distinct D1.c1 + 1 as c1,
         D1.c2 as c2
    from
         SAWITH1 D1),
    SAWITH3 AS (select Case when case D1.c5 when 1 then D1.c3 else NULL end  is not null then Rank() OVER ( ORDER BY case D1.c5 when 1 then D1.c3 else NULL end  ASC NULLS LAST ) end as c1,
         D1.c6 as c2,
         D1.c4 as c3
    from
         OBICOMMON0 D1),
    SAWITH4 AS (select distinct min(D1.c1) over (partition by D1.c3)  as c1,
         D1.c2 as c2,
         D1.c3 as c3
    from
         SAWITH3 D1),
    SAWITH5 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
         D4.c2 as c2,
         T41894.ICN_GROUP as c3,
         T30728.PARENT_REGION as c4,
         D4.c3 as c5,
         T41894.ICN_GROUP_CODE as c6
    from
         SAWITH2 D6 left outer join (
                        XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
                        XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
                   XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T37838.OVERRIDE_ICN = T41894.ICN_CODE) On D6.c2 = T37838.PERIOD_NAME,
         SAWITH4 D4
    where  ( D4.c1 = D6.c1 and D4.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
    group by T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP, D4.c2, D4.c3),
    SAWITH6 AS (select sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
         sum(case  when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2,
         T28761.QUARTER_YEAR_NAME as c3,
         T41894.ICN_GROUP as c4,
         T30728.PARENT_REGION as c5,
         T28761.QUARTER_RANK as c6,
         T41894.ICN_GROUP_CODE as c7
    from
                        XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */  left outer join
                        XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T37838.PERIOD_NAME) left outer join
                   XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
              XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T37838.OVERRIDE_ICN = T41894.ICN_CODE
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
    group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
    SAWITH7 AS (select sum(T34877.AMOUNT) as c1,
         T28761.QUARTER_YEAR_NAME as c2,
         T41894.ICN_GROUP as c3,
         T30728.PARENT_REGION as c4,
         T28761.QUARTER_RANK as c5,
         T41894.ICN_GROUP_CODE as c6
    from
                        XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */  left outer join
                        XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */  On T28761.PERIOD_NAME = T34877.PERIOD_NAME) left outer join
                   XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */  On T30728.COUNTRY_CODE = T34877.SHIP_TO_COUNTRY_CODE2) left outer join
              XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */  On T34877.OVERRIDE_ICN = T41894.ICN_CODE
    where  ( T28761.QUARTER_YEAR_NAME = '2010-Q2' )
    group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
    SAWITH8 AS (select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6,
         D1.c7 as c7,
         D1.c8 as c8,
         D1.c9 as c9,
         D1.c18 as c18,
         D1.c19 as c19,
         D1.c20 as c20,
         D1.c21 as c21,
         D1.c22 as c22
    from
         (select 0 as c1,
                   case  when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end  as c2,
                   case  when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end  as c3,
                   case  when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end  as c4,
                   case  when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end  as c5,
                   nvl(D2.c2 , 0) / nullif( nvl(D3.c1 , 0), 0) * 100 as c6,
                   D3.c1 / 1000 as c7,
                   D1.c1 / 1000 as c8,
                   D2.c1 / 1000 as c9,
                   case  when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end  as c18,
                   D2.c2 as c19,
                   D3.c1 as c20,
                   D1.c1 as c21,
                   D2.c1 as c22,
                   ROW_NUMBER() OVER (PARTITION BY case  when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end , case  when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end , case  when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end , case  when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end , case  when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end  ORDER BY case  when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end  ASC, case  when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end  ASC, case  when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end  ASC, case  when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end  ASC, case  when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end  ASC) as c23
              from
                        SAWITH5 D1 full outer join SAWITH6 D2 On D1.c6 = D2.c7 and  SYS_OP_MAP_NONNULL(D1.c4) = SYS_OP_MAP_NONNULL(D2.c5)  and  SYS_OP_MAP_NONNULL(D1.c5) = SYS_OP_MAP_NONNULL(D2.c6) ) full outer join SAWITH7 D3 On D3.c6 = case  when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 end  and  SYS_OP_MAP_NONNULL(D3.c4) = SYS_OP_MAP_NONNULL(case  when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 end )  and  SYS_OP_MAP_NONNULL(D3.c5) = SYS_OP_MAP_NONNULL(case  when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 end )
         ) D1
    where  ( D1.c23 = 1 ) )
    select D1.c1 as c1,
         D1.c2 as c2,
         D1.c3 as c3,
         D1.c4 as c4,
         D1.c5 as c5,
         D1.c6 as c6,
         D1.c7 as c7,
         D1.c8 as c8,
         D1.c9 as c9,
         D1.c18 as c19,
         D1.c19 as c21,
         D1.c20 as c22,
         D1.c21 as c23,
         D1.c22 as c24
    from
         SAWITH8 D1
    order by c4, c2, c5, c19, c3
    [2013-08-14T10:38:15.000-05:00] [OracleBIServerComponent] [TRACE:2] [USER-34] [] [ecid: 54a0696aeaefab88:-d74da91:1406506ef2a:-8000-00000000000151e6,0:1:9:6:1] [tid: a093e700] [requestid: cc480014] [sessionid: cc480000] [username: ] -------------------- Query Status: Successful Completion [[
    [2013-08-14T10:38:15.000-05:00] [OracleBIServerComponent] [TRACE:2] [USER-26] [] [ecid: 54a0696aeaefab88:-d74da91:1406506ef2a:-8000-00000000000151e6,0:1:9:6:1] [tid: a093e700] [requestid: cc480014] [sessionid: cc480000] [username: ] -------------------- Rows 17, bytes 27200 retrieved from database query id: <<2779207>>

    check the report for the columns which has incorrect values for any calculation, null handling.
    also check whether there is a difference in logical SQL between 10g and 11g.
    also check whether they are pointing to same db.
    check for null handling or default value not being set in 11g.
    try rebuilding the same report, to check the metrics individually verify they match with 10g.

  • 11g: Multicolumn pivot - help with query

    Hi everyone,
    My first attempt at posting here was not very successful. I have now read the rules, and done more homework.
    I'm fairly new to Oracle databases, but have some experience with MySQL and Postgres from earlier.
    First of all, here is an example table of what I have today. This is only an extract of the full table, but these fields are the interesting ones.
    CREATE TABLE trans
         ("FROM_LIC" int, "FROM_LOCATION" varchar2(18), "TO_LOCATION" varchar2(18), "CREATE_DT" timestamp)
    INSERT ALL
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, '215', 'INN_MONO_05', '04-Mar-2013 11:54:21 AM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'INN_MONO_05', 'INN_MONO_06_BANE_R', '04-Mar-2013 11:55:08 AM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'INN_MONO_06_BANE_R', 'TROLLEY_19', '04-Mar-2013 12:01:06 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'TROLLEY_19', 'UT_OPPLAST_5_2', '04-Mar-2013 12:01:56 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100002563, 'UT_OPPLAST_5_2', 'STG010801', '04-Mar-2013 12:01:56 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'INN_MONO_04', 'INN_MONO_04_BANE_L', '04-Mar-2013 02:19:28 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'INN_MONO_04_BANE_L', 'TROLLEY_5', '04-Mar-2013 02:22:41 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003259, 'TROLLEY_5', 'UT_OPPLAST_3_1', '04-Mar-2013 02:23:35 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, '243', 'INN_MONO_06', '04-Mar-2013 01:37:49 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'INN_MONO_06', 'INN_MONO_06_BANE_R', '04-Mar-2013 01:39:09 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'INN_MONO_06_BANE_R', 'TROLLEY_10', '04-Mar-2013 01:43:48 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'TROLLEY_10', 'UT_OPPLAST_5_2', '04-Mar-2013 01:44:58 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003262, 'UT_OPPLAST_5_2', 'STG010904', '04-Mar-2013 01:46:30 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003263, '231', 'INN_MONO_04', '04-Mar-2013 02:18:31 PM')
         INTO trans ("FROM_LIC", "FROM_LOCATION", "TO_LOCATION", "CREATE_DT")
               VALUES (4100003263, 'INN_MONO_04', 'INN_MONO_04_BANE_R', '04-Mar-2013 02:19:20 PM')
    SELECT * FROM dual
    ;As of now, I have a query that returns a data grid from the table, looking exactly like the example table I've included.
    Here is a copy of the query that gives the example table as a result from the table in our database:
    select * from (
        select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)
        union
        select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)
      ) order by from_lic, create_dtI would be delighted if you could help me formulating a new query that gives THIS output, from the same table, with the same constraints as in the original query:
    CREATE TABLE new_table
         ("FROM_LIC" int, "FLOOR" timestamp, "INFEED" timestamp, "TROLLEY" timestamp, "OUTFEED" timestamp, "STAGING" varchar2(16))
    INSERT ALL
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100002563, '04-Mar-2013 11:54:00 AM', '04-Mar-2013 11:55:00 AM', '04-Mar-2013 12:01:00 PM', '04-Mar-2013 12:01:00 PM', '03.04.2013 12:01')
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100003259, '04-Mar-2013 02:18:00 PM', '04-Mar-2013 02:19:00 PM', '04-Mar-2013 02:22:00 PM', '04-Mar-2013 02:23:00 PM', NULL)
         INTO new_table ("FROM_LIC", "FLOOR", "INFEED", "TROLLEY", "OUTFEED", "STAGING")
               VALUES (4100003262, '04-Mar-2013 01:37:00 PM', '04-Mar-2013 01:39:00 PM', '04-Mar-2013 01:43:00 PM', '04-Mar-2013 01:44:00 PM', '03.04.2013 13:46')
    SELECT * FROM dual
    ;What happened here is that for each instance of from_lic, the line yielded from
    select distinct from_lic, from_location, to_location, create_dt from trans where to_location like 'INN_MONO___' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> in the new column called FLOOR.
    And the following for the rest of the columns:
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO___' and to_location like 'INN_MONO%BANE%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> INFEED.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'INN_MONO%BANE%' and to_location like 'TROLLEY%' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> TROLLEY.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'TROLLEY%' and to_location like 'UT_OPPLAST____' and create_dt > sysdate-(3/24)The value for CREATE_DT ---> OUTFEED.
    select distinct from_lic, from_location, to_location, create_dt from trans where from_location like 'UT_OPPLAST____%' and (to_location like 'STG%' or to_location like 'UT_OPPLAST%GULV') and create_dt > sysdate-(3/24)The value for CREATE_DT ---> STAGING.
    Originally I was thinking of a pivot for this, but there is possibly better ways to accomplish this.
    I would like to have the data in the described format to make data mining easier.
    The query will run on a table with >3M lines.
    I hope this way of formulating the question is better, and more comprehensible.
    Please do not hesitate to ask questions, and I'll do my best to answer.
    I can test any suggested queries in the production database when necessary.
    Edited by: 997749 on Apr 3, 2013 5:18 AM
    Edited by: 997749 on Apr 3, 2013 6:20 AM

    Hi,
    what about something like this:
    with trans as
       SELECT 4100002563 from_lic, 'INN_MONO_05'        to_location, TO_DATE('03.04.2013 11:54:21', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'INN_MONO_06_BANE_R' to_location, TO_DATE('03.04.2013 11:55:08', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'TROLLEY_19'         to_location, TO_DATE('03.04.2013 12:01:06', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'STG010801'          to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100002563 from_lic, 'UT_OPPLAST_5_2'     to_location, TO_DATE('03.04.2013 12:01:56', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'INN_MONO_05'        to_location, TO_DATE('03.04.2013 11:18:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'INN_MONO_04_BANE_R' to_location, TO_DATE('03.04.2013 11:21:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'TROLLEY_16'         to_location, TO_DATE('03.04.2013 11:25:43', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'UT_OPPLAST_3_4'     to_location, TO_DATE('03.04.2013 11:26:37', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100005037 from_lic, 'STG010703'          to_location, TO_DATE('03.04.2013 11:27:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'INN_MONO_08'        to_location, TO_DATE('03.04.2013 11:00:31', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'INN_MONO_08_BANE_L' to_location, TO_DATE('03.04.2013 11:02:35', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'TROLLEY_22'         to_location, TO_DATE('03.04.2013 11:07:54', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL UNION ALL
       SELECT 4100006658 from_lic, 'UT_OPPLAST_7_3'     to_location, TO_DATE('03.04.2013 11:09:03', 'DD.MM.YYYY HH24:MI:SS') create_dt FROM DUAL
    , got_category AS
       SELECT from_lic
            , CASE
                 WHEN to_location like 'INN_MONO%BANE%'
                 THEN 'INFEED'
                 WHEN to_location like 'INN_MONO%'
                 THEN 'FLOOR'
                 WHEN to_location like 'TROLLEY%'
                 THEN 'TROLLEY'
                 WHEN to_location like 'STG' OR to_location like 'UT%GULV' 
                 THEN 'STAGED'
                 WHEN to_location like 'UT_OPPLAST%'
                 THEN 'OUTFEED'
                 ELSE 'UNKNOWN'
              END as cat
            , create_dt
         FROM trans
        WHERE create_dt > (sysdate -10/24) -- adjusted for different timezone
    SELECT * --FROM_LIC, lic_a, lic_b, lic_c, lic_d, lic_e
      FROM got_category
    PIVOT(MAX(create_dt) FOR cat IN('FLOOR'   as floor,
                                     'INFEED'  as infeed,
                                     'TROLLEY' as trolley,
                                     'OUTFEED' as ooutfeed,
                                     'STAGED'  as staged));
      FROM_LIC FLOOR                  INFEED                 TROLLEY                OOUTFEED               STAGED               
    4100002563 03-APR-2013 11:54:21   03-APR-2013 11:55:08   03-APR-2013 12:01:06   03-APR-2013 12:01:56                        
    4100005037 03-APR-2013 11:18:31   03-APR-2013 11:21:54   03-APR-2013 11:25:43   03-APR-2013 11:26:37                        
    4100006658 03-APR-2013 11:00:31   03-APR-2013 11:02:35   03-APR-2013 11:07:54   03-APR-2013 11:09:03                         If not useful, please post your input data (CREATE TABLE and INSERT statements) and your expected output.
    Regards.
    Al

Maybe you are looking for