Union All in a Subquery - Help

Hello All,
I am trying to create a Union All query but when i put a parameter in the where clause, i get an error. The Query is mentioned below:
SELECT     T0.U_Srv_TechName, T0.ItemCode, T0.Dscription, SUM(T0.Quantity) AS [Bal Qty]
FROM         (SELECT     dbo.OWTR.U_Srv_TechName, dbo.WTR1.ItemCode, dbo.WTR1.Dscription, SUM(dbo.WTR1.Quantity) AS Quantity
                       FROM          dbo.OWTR INNER JOIN
                                              dbo.WTR1 ON dbo.OWTR.DocEntry = dbo.WTR1.DocEntry
                       GROUP BY dbo.OWTR.U_Srv_TechName, dbo.WTR1.ItemCode, dbo.WTR1.Dscription
                       UNION ALL
                       SELECT     dbo.ODLN.U_Srv_TechName, dbo.DLN1.ItemCode, dbo.DLN1.Dscription, SUM(dbo.DLN1.Quantity * - 1) AS Quantity
                       FROM         dbo.ODLN INNER JOIN
                                             dbo.DLN1 ON dbo.ODLN.DocEntry = dbo.DLN1.DocEntry
                       GROUP BY dbo.ODLN.U_Srv_TechName, dbo.DLN1.ItemCode, dbo.DLN1.Dscription) T0
GROUP BY T0.U_Srv_TechName, T0.ItemCode, T0.Dscription
HAVING T0.U_Srv_TechName = [%0]
It gives me the error
1). [Microsoft][SQL Native Client][SQL Server]Must specify table to select from.
2). [Microsoft][SQL Native Client][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
If I enter the name of the Technician (HAVING T0.U_Srv_TechName = 'xyz') it works fine. Also, if I execute the query in SQL Server with or without a prompt, it works fine. It's only on the SAP Query Manager that i'm having this problem. Please Help!
Reza

Reza,
Try this modification of the previous code, see if it works for you.
declare @stn varchar(20)
set @stn=/*SELECT T0.[DocNum] FROM OWTR T0 WHERE T0.[U_Srv_TechName] =*/'[%0]'
SELECT     T0.U_Srv_TechName, T0.ItemCode, T0.Dscription, SUM(T0.Quantity) AS [Bal Qty]
FROM         (SELECT     T0.U_Srv_TechName, T1.ItemCode, T1.Dscription, SUM(T1.Quantity) AS Quantity
                       FROM          OWTR T0 INNER JOIN
                                              WTR1 T1 ON T0.DocEntry = T1.DocEntry
                       GROUP BY T0.U_Srv_TechName, T1.ItemCode, T1.Dscription
                       UNION ALL
                       SELECT     T2.U_Srv_TechName, T3.ItemCode, T3.Dscription, SUM(T3.Quantity * - 1) AS Quantity
                       FROM         ODLN T2 INNER JOIN
                                             DLN1 T3 ON T2.DocEntry = T3.DocEntry
                       GROUP BY T2.U_Srv_TechName, T3.ItemCode, T3.Dscription) T0
GROUP BY T0.U_Srv_TechName, T0.ItemCode, T0.Dscription
HAVING T0.U_Srv_TechName =@stn
Hope this helps,
Lucas

Similar Messages

  • Materalized view with union all and fast referesh

    I have a one view which is very slow. in this view we are joining many tables and many union all queries.
    now I am planing to make materalized view
    Tell me how i will created view with fast refresh with union all query.
    Pls help its urgent..
    Thanks
    Reena

    Refer to the Replication Manual for the create syntax and exceptions.

  • Help in union all with 3 queries

    could anyone help me in using union all or other method to combine the below 3 queries??
    ************* 1st Query   ************
    WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
        value ,
        CASE metricid WHEN 16 THEN 'FCR' ELSE 'Cases' END AS metric
    FROM XXXXXX AS V
    WHERE metricid IN (16, 11)
    AND row_date BETWEEN '2012-01-01' AND '2014-10-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'Cases',
        metric 
    FROM a
    WHERE metric = 'cases')
    , c AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'FCR',
        metric
    FROM a
    WHERE metric = 'FCR')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.FCR, b.Cases 
    FROM b INNER JOIN c 
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year] 
    AND c.[month] = b.[month]
    WHERE c.fcr <> 0 AND b.cases <> 0
    ,E AS (
    SELECT [Year], [Month], SUM(FCR) AS FCR, SUM(Cases) AS Cases
    FROM d
    GROUP BY [Year], [Month])
    select YEAR, MONTH, 
    CASE MONTH 
    WHEN 1 THEN 'Jan'
    WHEN 2 THEN 'Feb'
    WHEN 3 THEN 'Mar'
    WHEN 4 THEN 'Apr'
    WHEN 5 THEN 'May'
    WHEN 6 THEN 'Jun'
    WHEN 7 THEN 'Jul'
    WHEN 8 THEN 'Aug'
    WHEN 9 THEN 'Sep'
    WHEN 10 THEN 'Oct'
    WHEN 11 THEN 'Nov'
    WHEN 12 THEN 'Dec'
    END AS MonthName
    ,e.FCR AS FCRCases
    ,e.Cases AS TotalCases
    ,CASE 
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    --,CONVERT(DECIMAL(18, 2),(e.FCR/e.Cases)*100) AS FCRRaw
    from e
    order by YEAR, MONTH
    **************2nd query*************
    WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
        value, 
        CASE metricid WHEN 56 THEN 'numerator' ELSE 'denominator' END AS metric
    FROM XXXXXXX.[Values] AS V
    WHERE metricid IN (56, 10)
    --WHERE metricid IN (11,16)
    AND row_date BETWEEN '2013-10-01' AND '2014-02-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'numerator',
        metric
    FROM a
    WHERE metric = 'numerator')
    , c AS (
    SELECT     clientid ,
        Year ,
        Month ,
        value AS 'denominator',
        metric
    FROM a
    WHERE metric = 'denominator')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.denominator, b.numerator 
    FROM b INNER JOIN c 
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year] 
    AND c.[month] = b.[month]
    WHERE c.denominator <> 0 AND b.numerator <> 0
    , e AS (
    SELECT [Year], [Month], SUM(numerator) AS numerator, SUM(denominator) AS denominator
    FROM d
    GROUP BY [Year], [Month]
    SELECT *, 
    CASE 
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    FROM e
    ORDER BY 1,2
    ******************3rd query**************
    WITH a AS (
    SELECT --L.[LocationGroupId],
    -- T.locationid,
    -- T.AccountId,
    TR.datestamp,
    /*Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01'*/ 
    TR.Period AS ValueDate,
    CASE WHEN TR.TargetResultState = 0 THEN 0 WHEN TR.TargetResultState = 1 THEN 1 WHEN TR.TargetResultState = 2 THEN 1 ELSE 0 END AS Met,
    CASE WHEN CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') > T.Startdate AND CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp))
    + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') < T.Enddate THEN 1 ELSE 0 END AS ActiveTarget
    FROM XXXXXX AS TR
    INNER JOIN dbo.Target T ON TR.TargetID = T.ID
    --INNER JOIN dbo.Location L ON T.Locationid = L.Id
    WHERE --locationid <> - 1 AND 
    TR.Period IN ('201306', '201307', '201308', '201309', '201310', '201311', '201312', '201401'))
    select ValueDate, SUM(Met) AS Met, Count(ActiveTarget) AS ActiveTargets,
    right(ValueDate,2) as Month
    ,left(ValueDate,4) as Year
    ,CASE 
    WHEN right(ValueDate,2) IN (11, 12, 1) THEN 1
    WHEN right(ValueDate,2) IN (2, 3, 4) THEN 2
    WHEN right(ValueDate,2) IN (5, 6, 7) THEN 3
    WHEN right(ValueDate,2) IN (8, 9, 10) THEN 4
    END AS 'Quarter'
    from a
    group by ValueDate
    order by ValueDate

    Try the below:(Not tested)
    create table #temp (Year int,month int,Monthname char(3),FCRCases varchar(50),Cases varchar(50),Quater int,valuedate date,Met int,ActiveTargets int)
    WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
    value ,
    CASE metricid WHEN 16 THEN 'FCR' ELSE 'Cases' END AS metric
    FROM XXXXXX AS V
    WHERE metricid IN (16, 11)
    AND row_date BETWEEN '2012-01-01' AND '2014-10-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT clientid ,
    Year ,
    Month ,
    value AS 'Cases',
    metric
    FROM a
    WHERE metric = 'cases')
    , c AS (
    SELECT clientid ,
    Year ,
    Month ,
    value AS 'FCR',
    metric
    FROM a
    WHERE metric = 'FCR')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.FCR, b.Cases
    FROM b INNER JOIN c
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year]
    AND c.[month] = b.[month]
    WHERE c.fcr <> 0 AND b.cases <> 0
    ,E AS (
    SELECT [Year], [Month], SUM(FCR) AS FCR, SUM(Cases) AS Cases
    FROM d
    Insert into #temp(year,month,monthname,FCRCases,Cases,Quater,Valuedate,Met,ActiveTargets)
    select YEAR, MONTH,
    CASE MONTH
    WHEN 1 THEN 'Jan'
    WHEN 2 THEN 'Feb'
    WHEN 3 THEN 'Mar'
    WHEN 4 THEN 'Apr'
    WHEN 5 THEN 'May'
    WHEN 6 THEN 'Jun'
    WHEN 7 THEN 'Jul'
    WHEN 8 THEN 'Aug'
    WHEN 9 THEN 'Sep'
    WHEN 10 THEN 'Oct'
    WHEN 11 THEN 'Nov'
    WHEN 12 THEN 'Dec'
    END AS MonthName
    ,e.FCR AS FCRCases
    ,e.Cases AS TotalCases
    ,CASE
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter',NULL,NULL,NULL
    --,CONVERT(DECIMAL(18, 2),(e.FCR/e.Cases)*100) AS FCRRaw
    from e
    order by YEAR, MONTH
    **************2nd query*************
    WITH a AS (
    SELECT
    clientid,
    DATEPART(year, row_date) AS 'Year',
    DATEPART(month, row_date) AS 'Month',
    value,
    CASE metricid WHEN 56 THEN 'numerator' ELSE 'denominator' END AS metric
    FROM XXXXXXX.[Values] AS V
    WHERE metricid IN (56, 10)
    --WHERE metricid IN (11,16)
    AND row_date BETWEEN '2013-10-01' AND '2014-02-01'
    AND value IS NOT NULL)
    , b AS (
    SELECT clientid ,
    Year ,
    Month ,
    value AS 'numerator',
    metric
    FROM a
    WHERE metric = 'numerator')
    , c AS (
    SELECT clientid ,
    Year ,
    Month ,
    value AS 'denominator',
    metric
    FROM a
    WHERE metric = 'denominator')
    , d AS (
    SELECT b.YEAR, b.MONTH, c.denominator, b.numerator
    FROM b INNER JOIN c
    ON c.clientid = b.clientid
    AND c.[YEAR] = b.[year]
    AND c.[month] = b.[month]
    WHERE c.denominator <> 0 AND b.numerator <> 0
    , e AS (
    SELECT [Year], [Month], SUM(numerator) AS numerator, SUM(denominator) AS denominator
    FROM d
    GROUP BY [Year], [Month]
    Insert into #temp(year,month,monthname,FCRCases,Cases,Quater,Valuedate,Met,ActiveTargets)
    SELECT year,month,
    CASE MONTH
    WHEN 1 THEN 'Jan'
    WHEN 2 THEN 'Feb'
    WHEN 3 THEN 'Mar'
    WHEN 4 THEN 'Apr'
    WHEN 5 THEN 'May'
    WHEN 6 THEN 'Jun'
    WHEN 7 THEN 'Jul'
    WHEN 8 THEN 'Aug'
    WHEN 9 THEN 'Sep'
    WHEN 10 THEN 'Oct'
    WHEN 11 THEN 'Nov'
    WHEN 12 THEN 'Dec'
    END AS MonthName, NULL,NULL,
    CASE
    WHEN [month] IN (11, 12, 1) THEN 1
    WHEN [month] IN (2, 3, 4) THEN 2
    WHEN [month] IN (5, 6, 7) THEN 3
    WHEN [month] IN (8, 9, 10) THEN 4
    END AS 'Quarter',NULL,NULL,NULL
    FROM e
    ******************3rd query**************
    WITH a AS (
    SELECT --L.[LocationGroupId],
    -- T.locationid,
    -- T.AccountId,
    TR.datestamp,
    /*Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01'*/
    TR.Period AS ValueDate,
    CASE WHEN TR.TargetResultState = 0 THEN 0 WHEN TR.TargetResultState = 1 THEN 1 WHEN TR.TargetResultState = 2 THEN 1 ELSE 0 END AS Met,
    CASE WHEN CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') > T.Startdate AND CONVERT(DATE, Convert(NVARCHAR, DatePArt(year, TR.datestamp)) + '-' + Convert(NVARCHAR, DatePArt(month, TR.datestamp)) + '-01') < T.Enddate THEN 1 ELSE 0 END AS ActiveTarget
    FROM XXXXXX AS TR
    INNER JOIN dbo.Target T ON TR.TargetID = T.ID
    --INNER JOIN dbo.Location L ON T.Locationid = L.Id
    WHERE --locationid <> - 1 AND
    TR.Period IN ('201306', '201307', '201308', '201309', '201310', '201311', '201312', '201401'))
    create table #temp (Year int,month int,Monthname char(3),FCRCases varchar(50),Cases varchar(50),Quater int,valuedate date,Met int,ActiveTargets int)
    Insert into temp (year,month,monthname,FCRCases,Cases,Quater,Valuedate,Met,ActiveTargets)
    select
    right(ValueDate,2) as Month
    ,left(ValueDate,4) as Year,
    CASE right(ValueDate,2)
    WHEN 1 THEN 'Jan'
    WHEN 2 THEN 'Feb'
    WHEN 3 THEN 'Mar'
    WHEN 4 THEN 'Apr'
    WHEN 5 THEN 'May'
    WHEN 6 THEN 'Jun'
    WHEN 7 THEN 'Jul'
    WHEN 8 THEN 'Aug'
    WHEN 9 THEN 'Sep'
    WHEN 10 THEN 'Oct'
    WHEN 11 THEN 'Nov'
    WHEN 12 THEN 'Dec'
    END AS MonthName,NULL,NULL,
    ,CASE
    WHEN right(ValueDate,2) IN (11, 12, 1) THEN 1
    WHEN right(ValueDate,2) IN (2, 3, 4) THEN 2
    WHEN right(ValueDate,2) IN (5, 6, 7) THEN 3
    WHEN right(ValueDate,2) IN (8, 9, 10) THEN 4
    END AS 'Quarter',
    ValueDate, SUM(Met) AS Met, Count(ActiveTarget) AS ActiveTargets
    from a
    group by ValueDate
    Select distinct year,month,monthname,FCRCases,Cases,Quater,Valuedate,Met,ActiveTargets From #temp

  • Select Union All - group by help

    I have this Query with me
    select Item_number , Total_Supplier_Qty, Total_Customer_Qty,Ship_from_org_name,inventory_item_id ,Total_onhand, min, max
    from
    select NULL AS Total_Supplier_Qty,sum(eoo.ordered_quantity) Total_Customer_Qty,
    eoo.item_number Item_number,eoo.ship_from_org_name  Ship_from_org_name,eoo.inventory_item_id
    ,Total_onhand, min,max
    from   eoo
    group by eoo.item_number,eoo.ship_from_org_name ,eoo.inventory_item_id
    UNION ALL
    select eos.QUANTITY Total_Supplier_Qty,NULL AS Total_Customer_Qty,
    eos.item_number Item_number,eos.Ship_from_org_name  Ship_from_org_name,eos.inventory_item_id
    ,Total_onhand, min, max
    from  eos group by eos.item_number,eos.ship_from_org_name ,eos.QUANTITY ,eos.inventory_item_id
    GROUP BY   
      Total_Supplier_Qty, Total_Customer_Qty,Item_number,  Ship_from_org_name,inventory_item_id
    ,Total_onhand, min, max
    order by Item_numbergiving me result
    1901,     -     *,5*     ,71317,     12,     4     ,6
    1901     ,*6,*     -     ,71317,     12,     4,     6
    I want result combined
    1901,     6,     5,     71317,     12,     4,     6
    Help please.

    select  Item_number,
            SUM(Total_Supplier_Qty) Total_Supplier_Qty,
            SUM(Total_Customer_Qty) Total_Customer_Qty,
            Ship_from_org_name,
            inventory_item_id,
            Total_onhand,
            min,
            max
      from  (
              select  NULL AS Total_Supplier_Qty,
                      sum(eoo.ordered_quantity) Total_Customer_Qty,
                      eoo.item_number Item_number,
                      eoo.ship_from_org_name Ship_from_org_name,
                      eoo.inventory_item_id,
                      Total_onhand,
                      min,
                      max
               from  eoo
               group by eoo.item_number,
                        eoo.ship_from_org_name,
                        eoo.inventory_item_id
             UNION ALL
              select  eos.QUANTITY Total_Supplier_Qty,
                      NULL AS Total_Customer_Qty,
                      eos.item_number Item_number,
                      eos.Ship_from_org_name Ship_from_org_name,
                      eos.inventory_item_id,
                      Total_onhand,
                      min,
                      max
                from  eos
                group by eos.item_number,
                         eos.ship_from_org_name,
                         eos.QUANTITY,
                         eos.inventory_item_id
      GROUP BY Item_number,
               Ship_from_org_name,
               inventory_item_id,
               Total_onhand,
               min,
               max
      order by Item_numberSY.

  • Help : UNION ALL Query tuning

    Hi all,
    I want to fetch records from mview m_view1 joining the columns in table1 and table2.
    select mv1.col1,mv2.col2.., from mview1 mv1
    where mv1.col1 in (
    SELECT t1.col1
    FROM table1 t1
    WHERE t1.col2 = SUBSTR(user,3)
    UNION ALL
    SELECT t2.col1
    FROM table2 t2
    WHERE t2.col2 = SUBSTR(user,3)
    UNION ALL
    SELECT t1.col1
    FROM table1 t1, table2 t2
    WHERE t2.col2 = SUBSTR(user,3)
    AND t2.col1 = t1.col2
    Below is the explain plan I got :
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 616 | 2690 (1)| 00:00:33 |
    | 1 | NESTED LOOPS | | 1 | 616 | 2690 (1)| 00:00:33 |
    | 2 | VIEW | VW_NSO_1 | 2657 | 34541 | 30 (0)| 00:00:01 |
    | 3 | HASH UNIQUE | | 2657 | 61164 | 30 (90)| 00:00:01 |
    | 4 | UNION-ALL | | | | | |
    |* 5 | INDEX RANGE SCAN | table1_indx1      | 176 | 1760 | 3 (0)| 00:00:01 |
    |* 6 | INDEX RANGE SCAN | table2_prim1      | 14 | 196 | 2 (0)| 00:00:01 |
    | 7 | NESTED LOOPS | | 2467 | 59208 | 25 (0)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN | table2_prim1      | 14 | 196 | 2 (0)| 00:00:01 |
    |* 9 | INDEX RANGE SCAN | table1_indx2      | 176 | 1760 | 2 (0)| 00:00:01 |
    |* 10 | MAT_VIEW ACCESS BY INDEX ROWID| mview1                     | 1 | 603 | 1 (0)| 00:00:01 |
    |* 11 | INDEX UNIQUE SCAN | indx1                              | 1 | | 0 (0)| 00:00:01 |
    table1_indx2 - index on col1 & col2 of table1.
    table1_indx1 - index on col1 & col2 & col3 of table1.
    Im new to oracle tuning. Could you please help me in tuning this.
    Thanks in advance.

    Hi Rob,
    Given below the explain plan for the same:
    | Id  | Operation                       | Name                     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |                          |     1 |   616 |  2690   (1)| 00:00:33 |
    |   1 |  NESTED LOOPS                   |                          |     1 |   616 |  2690   (1)| 00:00:33 |
    |   2 |   VIEW                          | VW_NSO_1                 |  2657 | 34541 |    30   (0)| 00:00:01 |
    |   3 |    HASH UNIQUE                  |                          |  2657 | 61164 |    30  (90)| 00:00:01 |
    |   4 |     UNION-ALL                   |                          |       |       |            |          |
    |*  5 |      INDEX RANGE SCAN           | table1_indx1                 |   176 |  1760 |     3   (0)| 00:00:01 |
    |*  6 |      INDEX RANGE SCAN           | table2_prim1                |    14 |   196 |     2   (0)| 00:00:01 |
    |   7 |      NESTED LOOPS               |                          |  2467 | 59208 |    25   (0)| 00:00:01 |
    |*  8 |       INDEX RANGE SCAN          | table2_prim1                |    14 |   196 |     2   (0)| 00:00:01 |
    |*  9 |       INDEX RANGE SCAN          | table1_indx2                 |   176 |  1760 |     2   (0)| 00:00:01 |
    |* 10 |   MAT_VIEW ACCESS BY INDEX ROWID| mview1                        |     1 |   603 |     1   (0)| 00:00:01 |
    |* 11 |    INDEX UNIQUE SCAN            | indx1                               |     1 |       |     0   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------------------------------

  • Union All query help

    Hi,
    I have a union all query like this :
    select a.prod_id,count(a.app_id) as noofapplications from enrollment a,attest b
    where a.e_id=b.e_id group by a.prod_id
    union all
    select a.prod_id,count(a.app_id) as noofapplications from data_feed x,prod_feed y
    where x.agent_num=y.prod_id group by y.prod_id
    I get the results something like this :
    prod_id noofapplications
    x1824787 2
    y397458 4
    y397458 3
    r457868 3
    i876247 6
    In below results y397458 is showing twice since it results from both the queries .But i want a single result like this :
    prod_id noofapplications
    x1824787 2
    y397458 7
    r457868 3
    i876247 6
    For y397458 it should add 4+3 and the result should be displayed one time only .
    Please help ..
    Thanks in Advance

    Slightly reorder your query text:
    select prod_id,count(app_id) as noofapplications
    from
    select a.prod_id,a.app_id
    from enrollment a,attest b
    where a.e_id=b.e_id
    union all
    select a.prod_id,a.app_id
    from data_feed x,prod_feed y
    where x.agent_num=y.prod_id
    group by prod_id
    /

  • Help with slow union all

    Hi
    The problem Im having is that I had a query on sales order tables that used to take a couple of minutes to run. The user wanted contract orders to be added to the query and these were stored in different tables to the sales orders. I carried out union all joins in views and then applied the query to the views. Unfortunately it now takes 30 minutes to run.
    I apologise for the large post, I am just trying to provide enough information for someone to help me out.
    Any help will be greatly appreciated.
    Thanks
    Stephen
    The original query was:
    SELECT
    C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, BILL_HDR.RATE,
    BILL_SO.SO_SHIP_QTY, BILL_SO.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
    BILL_SO.AR_DOC,
    CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
    MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, BILL_SO.ITEM
    FROM
    AR_DOC, BILL_HDR, CUS_LOC, BILL_SO, ITEM, MEMO, C_STD_COST
    WHERE
    AR_DOC.AR_CCN=BILL_HDR.AR_CCN AND
    AR_DOC.AR_DOC_TYPE=BILL_HDR.AR_DOC_TYPE AND
    AR_DOC.AR_DOC=BILL_HDR.AR_DOC AND
    AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
    AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
    BILL_HDR.AR_CCN=BILL_SO.AR_CCN AND
    BILL_HDR.AR_DOC_TYPE=BILL_SO.AR_DOC_TYPE AND
    BILL_HDR.AR_DOC=BILL_SO.AR_DOC AND
    BILL_SO.ITEM=ITEM.ITEM (+) AND
    BILL_SO.REVISION=ITEM.REVISION (+) AND
    BILL_SO.AR_DOC=MEMO.AR_DOC (+) AND
    BILL_SO.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
    BILL_SO.AR_CCN=MEMO.SALES_CCN (+) AND
    BILL_SO.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
    ITEM.ITEM=C_STD_COST.ITEM (+) AND
    ITEM.REVISION=C_STD_COST.REVISION (+) AND
    AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS') AND
    AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS')
    ORDER BY
    AR_DOC.CUSTOMER, ITEM.PCThe explain plan showed:
    SELECT STATEMENT
    SORT                ORDER BY
    MERGE JOIN          OUTER
    SORT                JOIN
    NESTED LOOPS        OUTER
    NESTED LOOPS
    NESTED LOOPS
    NESTED LOOPS
    NESTED LOOPS        OUTER
    TABLE ACCESS        FULL              BILL_SO       4
    TABLE ACCESS        BY INDEX ROWID    ITEM          5
    INDEX               UNIQUE SCAN       PK_ITEM           UNIQUE
    TABLE ACCESS        BY INDEX ROWID    BILL_HDR      2
    INDEX               UNIQUE SCAN       PK_BILL_HDR       UNIQUE
    TABLE ACCESS        BY INDEX ROWID    AR_DOC        1
    INDEX               UNIQUE SCAN       PK_AR_DOC         UNIQUE
    TABLE ACCESS        BY INDEX ROWID    CUS_LOC       3
    INDEX               UNIQUE SCAN       PK_CUS_LOC        UNIQUE
    TABLE ACCESS        BY INDEX ROWID    MEMO          6
    INDEX               RANGE SCAN        PK_MEMO           UNIQUE
    SORT                JOIN
    TABLE ACCESS        FULL              COST_ITM      8The views I created were:
    CREATE VIEW C_BILL_DET AS
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
    REVISION, SO_SHIP_QTY, SO_SHIP_EXT_AMT, COST1
    FROM
    BILL_SO
    UNION ALL
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
    REVISION, SHIP_QTY, SHIP_EXT_AMT, COST1
    FROM
      CR_BLSH;
    CREATE VIEW C_BILL_HDR AS
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
    FROM
    BILL_HDR
    UNION ALL
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
    FROM
    CR_BLHD;The new query is:
    SELECT
    C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, C_BILL_HDR.RATE,
    C_BILL_DET.SO_SHIP_QTY, C_BILL_DET.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
    C_BILL_DET.AR_DOC,
    CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
    MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, C_BILL_DET.ITEM
    FROM
    AR_DOC, C_BILL_HDR, CUS_LOC, C_BILL_DET, ITEM, MEMO, C_STD_COST
    WHERE
    AR_DOC.AR_CCN=C_BILL_HDR.AR_CCN AND
    AR_DOC.AR_DOC_TYPE=C_BILL_HDR.AR_DOC_TYPE AND
    AR_DOC.AR_DOC=C_BILL_HDR.AR_DOC AND
    AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
    AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
    C_BILL_HDR.AR_CCN=C_BILL_DET.AR_CCN AND
    C_BILL_HDR.AR_DOC_TYPE=C_BILL_DET.AR_DOC_TYPE AND
    C_BILL_HDR.AR_DOC=C_BILL_DET.AR_DOC AND
    C_BILL_DET.ITEM=ITEM.ITEM (+) AND
    C_BILL_DET.REVISION=ITEM.REVISION (+) AND
    C_BILL_DET.AR_DOC=MEMO.AR_DOC (+) AND
    C_BILL_DET.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
    C_BILL_DET.AR_CCN=MEMO.SALES_CCN (+) AND
    C_BILL_DET.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
    ITEM.ITEM=C_STD_COST.ITEM (+) AND
    ITEM.REVISION=C_STD_COST.REVISION (+) AND
    AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS') AND
    AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS')
    ORDER BY
    AR_DOC.CUSTOMER, ITEM.PCThe explain plan is:
    SELECT STATEMENT
    SORT                ORDER BY
    MERGE JOIN          OUTER
    SORT                JOIN
    NESTED LOOPS
    NESTED LOOPS
    MERGE JOIN
    SORT                JOIN
    NESTED LOOPS        OUTER
    NESTED LOOPS        OUTER
    VIEW                                  C_BILL_DET   4
    UNION-ALL
    TABLE ACCESS        FULL              BILL_SO      9
    TABLE ACCESS        FULL              CR_BLSH      10
    TABLE ACCESS        BY INDEX ROWID    ITEM         5
    INDEX               UNIQUE SCAN       PK_ITEM           UNIQUE
    TABLE ACCESS        BY INDEX ROWID    MEMO         6
    INDEX               RANGE SCAN        PK_MEMO           UNIQUE
    SORT                JOIN
    VIEW                                  C_BILL_HDR   2
    UNION-ALL
    TABLE ACCESS        FULL              BILL_HDR     11
    TABLE ACCESS        FULL              CR_BLHD      12
    TABLE ACCESS        BY INDEX ROWID    AR_DOC       1
    INDEX               UNIQUE SCAN       PK_AR_DOC         UNIQUE
    TABLE ACCESS        BY INDEX ROWID    CUS_LOC      3
    INDEX               UNIQUE SCAN       PK_CUS_LOC        UNIQUE
    SORT                JOIN
    TABLE ACCESS        FULL              COST_ITM     8

    I don't understand.
    I try your with statement and get: "end_date" invalid identifier as an error
    I start my query out:
    WITH start_date as
    (select to_date ('08/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM') from dual),
    end_date as (select to_date ('08/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM) from dual)
    select sales.id, start_date as callstart, end_date as callend
    where sales.created_timestamp >= start_date
    and sales.created_timestamp < end_date
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with manufacturing>>>>>>>>>>>>>
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with engineering>>>>>>>>>>>>>
    and it still fails.

  • Help required on UNION ALL for select query

    Hello all,
    The execution plan for an SQL is impacted when another SELECT is concatenated with a UNION ALL. The two SELECTS are very efficient when run separately (< 100 buffer gets), but when run together (using a UNION ALL), the execution plan changes (for the first SELECT) and the buffer gets jumps to over 45000!
    what customer says with the UNION ALL, Oracle instead of doing a Merge Scan (that allows the inner table to filter out the rows from the outer table), chooses to do a NL join. This results in a Unique Index scan for each one of the 15000 rows in the outer table, resulting in 46000 consistent gets.
    Can you please suggest customer why plan changes when they use UNION ALL &  also suggest better way of running query.
    Please refer to below explain plan .
    WITH THE UNIONS
    ===============
      1  SELECT  count(*)
      2     FROM SOC_LIST SOC
      3     WHERE
      4       ( EXISTS(  SELECT  1
      5               FROM    ELIGIBILITY_RELATION
      6               WHERE   SRC_CODE = 'SHDMM4215'
      7                    AND   DEST_CODE = SOC.SOC
      8                 AND   SRC_TYPE = 'P'
      9                 AND   DEST_TYPE = 'S'))
    10  UNION ALL
    11   SELECT count(*)
    12     FROM SOC_LIST SOC
    13*    WHERE        ( = 'Y')
    12:25:39 SQL> /
      COUNT(*)                                                                                                                                           
           153                                                                                                                                           
             0                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=31 Card=2 Bytes=10)                                                                                
       1    0   UNION-ALL                                                                                                                                
       2    1     SORT (AGGREGATE)                                                                                                                       
       3    2       FILTER                                                                                                                               
       4    3         TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=749                                                                                
              Bytes=7490)                                                                                                                                
       5    3         PARTITION HASH (SINGLE)                                                                                                            
       6    5           INDEX (UNIQUE SCAN) OF 'ELIGIBILITY_RELATION_PK' (                                                                               
              UNIQUE) (Cost=2 Card=1 Bytes=24)                                                                                                           
       7    1     SORT (AGGREGATE)                                                                                                                       
       8    7       FILTER                                                                                                                               
       9    8         TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=1497                                                                               
              8)                                                                                                                                         
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
          46712  consistent gets         <------large number                                                                                                                 
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            215  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              0  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              2  rows processed                                                                                                                          
    12:25:40 SQL> ed
    Wrote file C:/PADDY/AFIEDT.BUF
    PART 1 of the UNION ALL
    ========================
      1  SELECT  count(*)
      2     FROM SOC_LIST SOC
      3     WHERE
      4       ( EXISTS(  SELECT  1
      5               FROM    ELIGIBILITY_RELATION
      6               WHERE   SRC_CODE = 'SHDMM4215'
      7                    AND   DEST_CODE = SOC.SOC
      8                 AND   SRC_TYPE = 'P'
      9*                AND   DEST_TYPE = 'S'))
    12:25:54 SQL> /
      COUNT(*)                                                                                                                                           
           153                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1 Bytes=34)                                                                                 
       1    0   SORT (AGGREGATE)                                                                                                                         
       2    1     MERGE JOIN (SEMI) (Cost=4 Card=149 Bytes=5066)                                                                                         
       3    2       INDEX (FULL SCAN) OF 'SOC_LIST_1IX' (NON-UNIQUE) (Cost                                                                               
              =41 Card=14978 Bytes=149780)                                                                                                               
       4    2       SORT (UNIQUE) (Cost=3 Card=149 Bytes=3576)                                                                                           
       5    4         PARTITION HASH (ALL)                                                                                                               
       6    5           INDEX (RANGE SCAN) OF 'ELIGIBILITY_RELATION_PK' (U                                                                               
              NIQUE) (Cost=10 Card=149 Bytes=3576)                                                                                                       
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
             56  consistent gets                                                                                                                         
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            218  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              1  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              1  rows processed                                                                                                                          
    12:25:55 SQL> ed
    Wrote file C:/PADDY/AFIEDT.BUF
    PART 2 of the UNION ALL
    ========================
      1   SELECT count(*)
      2     FROM SOC_LIST SOC
      3*    WHERE        ( = 'Y')
    12:26:15 SQL> /
      COUNT(*)                                                                                                                                           
             0                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=15 Card=1)                                                                                         
       1    0   SORT (AGGREGATE)                                                                                                                         
       2    1     FILTER                                                                                                                                 
       3    2       TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=14978)                                                                               
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
              0  consistent gets                                                                                                                         
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            215  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              0  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              1  rows processed                                                                                                                          
    12:26:20 SQL> spool off
    Same results but with theUNION ALL, the buffergets is massive ...
    Thanks
    Krishna

    i am also attaching 10043/10053 trace file .
    /opt/oracle/adm/STCUST/udump/stcust_ora_7919_10046_10053_trace_file.trc
    *** TRACE DUMP CONTINUED FROM FILE  ***
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    ORACLE_HOME = /opt/oracle/product/9.2.0.8
    System name: HP-UX
    Node name: rcihp009
    Release: B.11.23
    Version: U
    Machine: 9000/800
    Instance name: STCUST
    Redo thread mounted by this instance: 1
    Oracle process number: 152
    Unix process pid: 7919, image: oracle@rcihp009 (TNS V1-V3)
    *** 2013-06-10 13:32:48.943
    *** SESSION ID:(533.15875) 2013-06-10 13:32:48.943
    APPNAME mod='SQL*Plus' mh=3669949024 act='' ah=4029777240
    =====================
    PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017585934213 hv=2004533713 ad='4aa33998'
    alter session set events '10046 trace name context forever, level 12'
    END OF STMT
    EXEC #1:c=0,e=209,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017585933683
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:33:00.090
    WAIT #1: nam='SQL*Net message from client' ela= 10884599 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017596819944 hv=2030017677 ad='3af92970'
    alter session set events '10053 trace name context forever, level 1'
    END OF STMT
    PARSE #1:c=0,e=484,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017596819933
    BINDS #1:
    EXEC #1:c=0,e=160,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017596820180
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:33:50.197
    WAIT #1: nam='SQL*Net message from client' ela= 48932344 p1=1413697536 p2=1 p3=0
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    Column:        SOC  Col#: 3      Table: SOC_LIST   Alias: SOC
        NDV: 17584     NULLS: 0         DENS: 5.6870e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    Table stats    Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
      (Using composite stats)
      TOTAL ::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
    -- Index stats
      INDEX NAME: ELIGIBILITY_RELATION_1IX  COL#: 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 38360  #DK: 4164  LB/K: 9  DB/K: 740  CLUF: 3081860
      INDEX NAME: ELIGIBILITY_RELATION_PK  COL#: 2 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 50740  #DK: 11873160  LB/K: 1  DB/K: 1  CLUF: 9158280
      INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI  COL#: 1
        TOTAL ::  LVLS: 2   #LB: 49600  #DK: 11953600  LB/K: 1  DB/K: 1  CLUF: 8833300
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
    Column:   SRC_CODE  Col#: 2      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 22087     NULLS: 0         DENS: 4.5276e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:   SRC_TYPE  Col#: 3      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_TYPE  Col#: 5      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
      TABLE: ELIGIBILITY_RELATION     ORIG CDN: 11982220  ROUNDED CDN: 136  CMPTD CDN: 136
      Access path: tsc  Resc:  3072  Resp:  3072
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  1243  Resp:  1243
      Skip scan: ss-sel 0  andv 11970 
        ss cost 119700
        index io scan cost 19180
      Access path: index (scan)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 789653
      IX_SEL:  5.0000e-01  TB_SEL:  2.5000e-01
      Skip scan: ss-sel 0  andv 11970 
        ss cost 11970
        index io scan cost 2
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 10
      IX_SEL:  2.2638e-05  TB_SEL:  2.2638e-05
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 1.00  PATH: 4  Degree:  1
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      Access path: index (iff)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  3  Resp:  3
      Access path: index (no sta/stp keys)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 48
      IX_SEL:  1.0000e+00  TB_SEL:  1.0000e+00
      BEST_CST: 1.00  PATH: 4  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1
    Now joining: ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1 *******
    NL Join
      Outer table: cost: 1  cdn: 17584  rcz: 10  resp:  1
      Inner table: ELIGIBILITY_RELATION
        Access path: tsc  Resc: 768
        Join:  Resc:  13504513  Resp:  13504513
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Inner table: ELIGIBILITY_RELATION
        Access path: iff  Resc: 311
        Join:  Resc:  5464229  Resp:  5464229
      Access path: index (unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  8.3457e-08  TB_SEL:  8.3457e-08
        Join:  resc: 177  resp: 177
      Access path: index (join index)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 750
      IX_SEL:  0.0000e+00  TB_SEL:  2.0886e-05
        Join:  resc: 131881  resp: 131881
      Access path: index (eq-unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  0.0000e+00  TB_SEL:  0.0000e+00
        Join:  resc: 177  resp: 177
      ****** trying bitmap/domain indexes ******
      Access path: index (join index)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 10
      IX_SEL:  1.4217e-05  TB_SEL:  2.0886e-05
        Join:  resc: 1759  resp: 1759
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 4
      IX_SEL:  4.5276e-05  TB_SEL:  4.5276e-05
        Join:  resc: 704  resp: 704
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        2 Row size:           21 Rows:        543
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          3
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      ****** finished trying bitmap/domain indexes ******
      Best NL cost: 177  resp: 177
    Semi-join cardinality:  135 = outer (17584) * sel (7.6774e-03) [flag=12]
    SM Join
      Outer table:
        resc: 1  cdn: 17584  rcz: 10  deg: 1  resp: 1
      Inner table: ELIGIBILITY_RELATION
        resc: 1  cdn: 136  rcz: 24  deg:  1  resp: 1
        using join:1 distribution:2 #groups:1
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      Merge join  Cost:  4  Resp:  4
    HA Join
      Outer table:
        resc: 1  cdn: 17584  rcz: 10  deg: 1  resp: 1
      Inner table: ELIGIBILITY_RELATION
        resc: 1  cdn: 136  rcz: 24  deg:  1  resp: 1
        using join:8 distribution:2 #groups:1
      Hash join one ptn Resc: 4   Deg: 1
          hash_area:  154 (max=7680)  buildfrag:  48                probefrag:   1 ppasses:    1
      Hash join   Resc: 6   Resp: 6
    Join result: cost: 4  cdn: 135  rcz: 34
    Best so far: TABLE#: 0  CST:          1  CDN:      17584  BYTES:     175840
    Best so far: TABLE#: 1  CST:          4  CDN:        135  BYTES:       4590
    Join order[2]:  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1  SOC_LIST[SOC]#0
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
    Now joining: SOC_LIST[SOC]#0 *******
    NL Join
      Outer table: cost: 3  cdn: 136  rcz: 24  resp:  2
      Inner table: SOC_LIST
        Access path: tsc  Resc: 18
        Join:  Resc:  2450  Resp:  2450
      Access path: index (iff)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Inner table: SOC_LIST
        Access path: iff  Resc: 3
        Join:  Resc:  410  Resp:  410
      Access path: index (join index)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  0.0000e+00  TB_SEL:  5.6870e-05
        Join:  resc: 4  resp: 4
      Best NL cost: 4  resp: 4
    Join cardinality:  136 = outer (136) * inner (17584) * sel (5.6870e-05)  [flag=0]
    SM Join
      Outer table:
        resc: 2  cdn: 136  rcz: 24  deg: 1  resp: 2
      Inner table: SOC_LIST
        resc: 1  cdn: 17584  rcz: 10  deg:  1  resp: 1
        using join:1 distribution:2 #groups:1
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:       46 Row size:           21 Rows:      17584
          Initial runs:          1 Merge passes:        1 IO Cost / pass:         51
          Total IO sort cost: 48
          Total CPU sort cost: 0
          Total Temp space used: 0
      Merge join  Cost:  54  Resp:  54
    HA Join
      Outer table:
        resc: 2  cdn: 136  rcz: 24  deg: 1  resp: 2
      Inner table: SOC_LIST
        resc: 1  cdn: 17584  rcz: 10  deg:  1  resp: 1
        using join:8 distribution:2 #groups:1
      Hash join one ptn Resc: 1   Deg: 1
          hash_area:  154 (max=7680)  buildfrag:  1                probefrag:   48 ppasses:    1
      Hash join   Resc: 4   Resp: 4
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 4  CDN: 135  RSC: 4  RSP: 4  BYTES: 4590
      IO-RSC: 4  IO-RSP: 4  CPU-RSC: 0  CPU-RSP: 0
    QUERY
    SELECT   count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    =====================
    PARSING IN CURSOR #1 len=278 dep=0 uid=33 oct=3 lid=33 tim=3017645761269 hv=183981413 ad='492d5bb0'
    SELECT   count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    END OF STMT
    PARSE #1:c=10000,e=8343,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017645761258
    BINDS #1:
    EXEC #1:c=0,e=529,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017645761970
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='db file sequential read' ela= 9290 p1=2535 p2=142378 p3=1
    WAIT #1: nam='db file sequential read' ela= 2098 p1=2535 p2=142379 p3=1
    WAIT #1: nam='db file sequential read' ela= 11574 p1=2535 p2=33834 p3=1
    WAIT #1: nam='db file sequential read' ela= 10290 p1=2536 p2=60958 p3=1
    WAIT #1: nam='db file sequential read' ela= 11469 p1=2535 p2=61232 p3=1
    WAIT #1: nam='db file sequential read' ela= 378 p1=2535 p2=61233 p3=1
    WAIT #1: nam='db file sequential read' ela= 5493 p1=2535 p2=39498 p3=1
    WAIT #1: nam='db file sequential read' ela= 7397 p1=2536 p2=68185 p3=1
    WAIT #1: nam='db file sequential read' ela= 10037 p1=2536 p2=68520 p3=1
    WAIT #1: nam='db file sequential read' ela= 16125 p1=2535 p2=68809 p3=1
    WAIT #1: nam='db file sequential read' ela= 12426 p1=2535 p2=45162 p3=1
    WAIT #1: nam='db file sequential read' ela= 12447 p1=2535 p2=178335 p3=1
    WAIT #1: nam='db file sequential read' ela= 5974 p1=2535 p2=178798 p3=1
    WAIT #1: nam='db file sequential read' ela= 1247 p1=2535 p2=178799 p3=1
    WAIT #1: nam='db file sequential read' ela= 11010 p1=2535 p2=50826 p3=1
    WAIT #1: nam='db file sequential read' ela= 5421 p1=2536 p2=260451 p3=1
    WAIT #1: nam='db file sequential read' ela= 8230 p1=2536 p2=261538 p3=1
    WAIT #1: nam='db file sequential read' ela= 350 p1=2535 p2=142380 p3=1
    WAIT #1: nam='db file sequential read' ela= 346 p1=2535 p2=142381 p3=1
    WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142382 p3=1
    WAIT #1: nam='db file sequential read' ela= 480 p1=2535 p2=142383 p3=1
    WAIT #1: nam='db file sequential read' ela= 10237 p1=2535 p2=142384 p3=1
    WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142385 p3=1
    WAIT #1: nam='db file sequential read' ela= 359 p1=2535 p2=142386 p3=1
    WAIT #1: nam='db file sequential read' ela= 361 p1=2535 p2=142387 p3=1
    WAIT #1: nam='db file sequential read' ela= 375 p1=2535 p2=142388 p3=1
    WAIT #1: nam='db file sequential read' ela= 425 p1=2535 p2=142389 p3=1
    WAIT #1: nam='db file sequential read' ela= 540 p1=2535 p2=142390 p3=1
    WAIT #1: nam='db file sequential read' ela= 368 p1=2535 p2=142391 p3=1
    WAIT #1: nam='db file sequential read' ela= 479 p1=2535 p2=142392 p3=1
    WAIT #1: nam='db file sequential read' ela= 450 p1=2535 p2=142393 p3=1
    WAIT #1: nam='db file sequential read' ela= 307 p1=2535 p2=142394 p3=1
    WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142395 p3=1
    WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142396 p3=1
    WAIT #1: nam='db file sequential read' ela= 376 p1=2535 p2=142397 p3=1
    WAIT #1: nam='db file sequential read' ela= 295 p1=2535 p2=142398 p3=1
    WAIT #1: nam='db file sequential read' ela= 391 p1=2535 p2=142399 p3=1
    WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142400 p3=1
    WAIT #1: nam='db file sequential read' ela= 344 p1=2535 p2=142401 p3=1
    WAIT #1: nam='db file sequential read' ela= 337 p1=2535 p2=142402 p3=1
    WAIT #1: nam='db file sequential read' ela= 360 p1=2535 p2=142403 p3=1
    WAIT #1: nam='db file sequential read' ela= 402 p1=2535 p2=142404 p3=1
    WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142405 p3=1
    WAIT #1: nam='db file sequential read' ela= 408 p1=2535 p2=142406 p3=1
    WAIT #1: nam='db file sequential read' ela= 388 p1=2535 p2=142407 p3=1
    WAIT #1: nam='db file sequential read' ela= 400 p1=2535 p2=142408 p3=1
    WAIT #1: nam='db file sequential read' ela= 7999 p1=2536 p2=617 p3=1
    WAIT #1: nam='db file sequential read' ela= 520 p1=2536 p2=618 p3=1
    WAIT #1: nam='db file sequential read' ela= 294 p1=2536 p2=619 p3=1
    WAIT #1: nam='db file sequential read' ela= 311 p1=2536 p2=620 p3=1
    WAIT #1: nam='db file sequential read' ela= 316 p1=2536 p2=621 p3=1
    WAIT #1: nam='db file sequential read' ela= 306 p1=2536 p2=622 p3=1
    WAIT #1: nam='db file sequential read' ela= 303 p1=2536 p2=623 p3=1
    WAIT #1: nam='db file sequential read' ela= 1776 p1=2536 p2=624 p3=1
    FETCH #1:c=50000,e=216800,p=54,cr=54,cu=0,mis=0,r=1,dep=0,og=4,tim=3017645978865
    WAIT #1: nam='SQL*Net message from client' ela= 2802 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017645981803
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:34:28.160
    WAIT #1: nam='SQL*Net message from client' ela= 36844121 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=54 r=54 w=0 time=216788 us)'
    STAT #1 id=2 cnt=157 pid=1 pos=1 obj=0 op='MERGE JOIN SEMI (cr=54 r=54 w=0 time=216734 us)'
    STAT #1 id=3 cnt=14296 pid=2 pos=1 obj=5769123 op='INDEX FULL SCAN SOC_LIST_1IX (cr=39 r=39 w=0 time=55399 us)'
    STAT #1 id=4 cnt=157 pid=2 pos=2 obj=0 op='SORT UNIQUE (cr=15 r=15 w=0 time=141933 us)'
    STAT #1 id=5 cnt=286 pid=4 pos=1 obj=0 op='PARTITION HASH ALL PARTITION: 1 4 (cr=15 r=15 w=0 time=130847 us)'
    STAT #1 id=6 cnt=286 pid=5 pos=1 obj=5401812 op='INDEX RANGE SCAN ELIGIBILITY_RELATION_PK PARTITION: 1 4 (cr=15 r=15 w=0 time=130716 us)'
    QUERY
    BEGIN := 'N'; END;
    =====================
    PARSING IN CURSOR #1 len=23 dep=0 uid=33 oct=47 lid=33 tim=3017682828223 hv=16287806 ad='464edb18'
    BEGIN := 'N'; END;
    END OF STMT
    PARSE #1:c=0,e=1569,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017682828214
    BINDS #1:
    bind 0: dty=96 mxl=01(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=200071100000000 size=8 offset=0
       bfp=800003ffefe9f748 bln=01 avl=00 flg=05
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    EXEC #1:c=0,e=5494,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017682833795
    *** 2013-06-10 13:34:44.174
    WAIT #1: nam='SQL*Net message from client' ela= 15630899 p1=1413697536 p2=1 p3=0
    QUERY
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    =====================
    PARSING IN CURSOR #1 len=65 dep=0 uid=33 oct=3 lid=33 tim=3017698466665 hv=900106749 ad='43145458'
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    END OF STMT
    PARSE #1:c=0,e=1409,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017698466654
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0
    Best so far: TABLE#: 0  CST:         18  CDN:      17584  BYTES:          0
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 17584  RSC: 18  RSP: 18  BYTES: 0
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    BINDS #1:
    bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
       bfp=800003ffefea9490 bln=32 avl=01 flg=05
       value="N"
    EXEC #1:c=0,e=152,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017698469481
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    FETCH #1:c=10000,e=1506,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017698471536
    WAIT #1: nam='SQL*Net message from client' ela= 2607 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017698474268
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:07.656
    WAIT #1: nam='SQL*Net message from client' ela= 22922584 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=93 us)'
    STAT #1 id=2 cnt=0 pid=1 pos=1 obj=0 op='FILTER  (cr=0 r=0 w=0 time=29 us)'
    STAT #1 id=3 cnt=0 pid=2 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
    =====================
    PARSE ERROR #1:len=369 dep=0 uid=33 oct=0 lid=33 tim=3017721397730 err=900
    exec := 'N'
    SELEC ...
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2403 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:24.017
    WAIT #1: nam='SQL*Net message from client' ela= 15973854 p1=1413697536 p2=1 p3=0
    QUERY
    SELECT  count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    UNION ALL
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    =====================
    PARSING IN CURSOR #1 len=353 dep=0 uid=33 oct=3 lid=33 tim=3017737377655 hv=4202798596 ad='45639568'
    SELECT  count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    UNION ALL
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    END OF STMT
    PARSE #1:c=0,e=2624,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017737377644
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
      (Using composite stats)
      (adjusted for partition skews)
      ORIG STATS::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
      PARTCNT::
      PRUNED: 4  ANALYZED: 4  UNANALYZED: 0
      TOTAL ::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
    -- Index stats
      INDEX NAME: ELIGIBILITY_RELATION_1IX  COL#: 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 38360  #DK: 4164  LB/K: 9  DB/K: 740  CLUF: 3081860
      INDEX NAME: ELIGIBILITY_RELATION_PK  COL#: 2 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 50740  #DK: 11873160  LB/K: 1  DB/K: 1  CLUF: 9158280
      INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI  COL#: 1
        TOTAL ::  LVLS: 2   #LB: 49600  #DK: 11953600  LB/K: 1  DB/K: 1  CLUF: 8833300
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
    Column:   SRC_CODE  Col#: 2      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 22087     NULLS: 0         DENS: 4.5276e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_CODE  Col#: 4      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 11970     NULLS: 0         DENS: 8.3542e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:   SRC_TYPE  Col#: 3      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_TYPE  Col#: 5      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
      TABLE: ELIGIBILITY_RELATION     ORIG CDN: 11982220  ROUNDED CDN: 1  CMPTD CDN: 0
      Access path: tsc  Resc:  3072  Resp:  3072
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  1243  Resp:  1243
      Access path: index (unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 2
      IX_SEL:  8.3457e-08  TB_SEL:  8.3457e-08
      Access path: index (equal)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 68
      IX_SEL:  0.0000e+00  TB_SEL:  2.0886e-05
      Access path: index (eq-unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 2
      IX_SEL:  0.0000e+00  TB_SEL:  0.0000e+00
      ****** trying bitmap/domain indexes ******
      Access path: index (equal)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  2.0886e-05  TB_SEL:  2.0886e-05
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 5
      IX_SEL:  4.5276e-05  TB_SEL:  4.5276e-05
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        2 Row size:           21 Rows:        543
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          3
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      ****** finished trying bitmap/domain indexes ******
    One row CDN: 1
      BEST_CST: 1.00  PATH: 3  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#0
    Best so far: TABLE#: 0  CST:          1  CDN:          1  BYTES:         24
    Final - First Rows Plan:
      JOIN ORDER: 1
      CST: 1  CDN: 1  RSC: 1  RSP: 1  BYTES: 24
      IO-RSC: 1  IO-RSP: 1  CPU-RSC: 0  CPU-RSP: 0
      First Rows Plan
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SYS_ALIAS_1
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 879  CMPTD CDN: 879
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SYS_ALIAS_1]#0
    Best so far: TABLE#: 0  CST:         18  CDN:        879  BYTES:       8790
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 879  RSC: 18  RSP: 18  BYTES: 8790
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0
    Best so far: TABLE#: 0  CST:         18  CDN:      17584  BYTES:          0
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 17584  RSC: 18  RSP: 18  BYTES: 0
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    BINDS #1:
    bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
       bfp=800003ffefea9490 bln=32 avl=01 flg=05
       value="N"
    EXEC #1:c=0,e=159,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017737385286
    WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='db file sequential read' ela= 9958 p1=586 p2=128001 p3=1
    WAIT #1: nam='db file scattered read' ela= 619 p1=586 p2=128002 p3=4
    WAIT #1: nam='db file sequential read' ela= 12880 p1=2535 p2=39498 p3=1
    WAIT #1: nam='db file sequential read' ela= 39878 p1=2536 p2=68185 p3=1
    WAIT #1: nam='db file sequential read' ela= 10240 p1=2536 p2=68520 p3=1
    WAIT #1: nam='db file sequential read' ela= 15805 p1=2535 p2=45162 p3=1
    WAIT #1: nam='db file sequential read' ela= 11733 p1=2535 p2=178335 p3=1
    WAIT #1: nam='db file sequential read' ela= 11863 p1=2535 p2=178798 p3=1
    WAIT #1: nam='db file sequential read' ela= 4886 p1=2535 p2=33834 p3=1
    WAIT #1: nam='db file sequential read' ela= 12067 p1=2536 p2=60958 p3=1
    WAIT #1: nam='db file sequential read' ela= 16496 p1=2535 p2=61232 p3=1
    WAIT #1: nam='db file sequential read' ela= 8970 p1=2535 p2=50826 p3=1
    WAIT #1: nam='db file sequential read' ela= 10940 p1=2536 p2=260451 p3=1
    WAIT #1: nam='db file sequential read' ela= 8508 p1=2536 p2=261538 p3=1
    WAIT #1: nam='db file scattered read' ela= 32000 p1=1613 p2=4622 p3=35
    WAIT #1: nam='db file sequential read' ela= 1762 p1=2535 p2=178799 p3=1
    WAIT #1: nam='db file sequential read' ela= 341 p1=2535 p2=61233 p3=1
    WAIT #1: nam='db file scattered read' ela= 50494 p1=957 p2=230324 p3=35
    WAIT #1: nam='db file scattered read' ela= 36716 p1=5 p2=588169 p3=35
    WAIT #1: nam='db file scattered read' ela= 45241 p1=2326 p2=227427 p3=35
    WAIT #1: nam='db file sequential read' ela= 11783 p1=2535 p2=68809 p3=1
    WAIT #1: nam='db file scattered read' ela= 26720 p1=471 p2=102809 p3=35
    WAIT #1: nam='db file scattered read' ela= 31074 p1=1496 p2=97015 p3=35
    WAIT #1: nam='db file scattered read' ela= 39750 p1=586 p2=69452 p3=35
    WAIT #1: nam='db file scattered read' ela= 30923 p1=1613 p2=8636 p3=35
    WAIT #1: nam='db file scattered read' ela= 46328 p1=957 p2=67050 p3=35
    WAIT #1: nam='db file scattered read' ela= 34570 p1=5 p2=362823 p3=35
    WAIT #1: nam='db file scattered read' ela= 43343 p1=2326 p2=240311 p3=35
    WAIT #1: nam='db file scattered read' ela= 30818 p1=471 p2=76417 p3=35
    WAIT #1: nam='db file scattered read' ela= 19167 p1=1496 p2=480612 p3=35
    WAIT #1: nam='db file scattered read' ela= 26405 p1=586 p2=193036 p3=35
    WAIT #1: nam='db file scattered read' ela= 35374 p1=1613 p2=201565 p3=35
    WAIT #1: nam='db file scattered read' ela= 14275 p1=957 p2=15804 p3=7
    FETCH #1:c=190000,e=926019,p=552,cr=43429,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738311433
    WAIT #1: nam='SQL*Net message from client' ela= 2749 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=79,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738314443
    *** 2013-06-10 13:35:44.078
    WAIT #1: nam='SQL*Net message from client' ela= 18650883 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=2 pid=0 pos=1 obj=0 op='UNION-ALL  (cr=43429 r=552 w=0 time=926047 us)'
    STAT #1 id=2 cnt=1 pid=1 pos=1 obj=0 op='SORT AGGREGATE (cr=43429 r=552 w=0 time=925989 us)'
    STAT #1 id=3 cnt=157 pid=2 pos=1 obj=0 op='FILTER  (cr=43429 r=552 w=0 time=925909 us)'
    STAT #1 id=4 cnt=14296 pid=3 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST (cr=541 r=537 w=0 time=579577 us)'
    STAT #1 id=5 cnt=157 pid=3 pos=2 obj=0 op='PARTITION HASH SINGLE PARTITION: KEY KEY (cr=42888 r=15 w=0 time=285564 us)'
    STAT #1 id=6 cnt=157 pid=5 pos=1 obj=5401812 op='INDEX UNIQUE SCAN ELIGIBILITY_RELATION_PK PARTITION: KEY KEY (cr=42888 r=15 w=0 time=265355 us)'
    STAT #1 id=7 cnt=1 pid=1 pos=2 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=4 us)'
    STAT #1 id=8 cnt=0 pid=7 pos=1 obj=0 op='FILTER  (cr=0 r=0 w=0 time=1 us)'
    STAT #1 id=9 cnt=0 pid=8 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
    QUERY
    select 'close cursor' from dual
    =====================
    PARSING IN CURSOR #1 len=31 dep=0 uid=33 oct=3 lid=33 tim=3017756967074 hv=3487944275 ad='48de6a60'
    select 'close cursor' from dual
    END OF STMT
    PARSE #1:c=0,e=986,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017756967063
    BINDS #1:
    EXEC #1:c=0,e=47,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017756967278
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=134,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=4,tim=3017756967515
    WAIT #1: nam='SQL*Net message from client' ela= 2682 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017756970325
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:57.804
    WAIT #1: nam='SQL*Net message from client' ela= 13399621 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #3 len=116 dep=1 uid=0 oct=3 lid=0 tim=3017770371839 hv=431456802 ad='39fbad80'
    select o.owner#,o.name,o.namespace,o.remoteowner,o.linkname,o.subname,o.dataobj#,o.flags from obj$ o where o.obj#=:1
    END OF STMT
    PARSE #3:c=0,e=1249,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=3017770371828
    BINDS #3:
    bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0
       bfp=800003ffefea7a90 bln=22 avl=03 flg=05
       value=172
    EXEC #3:c=0,e=666,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=3017770372725
    WAIT #3: nam='db file sequential read' ela= 10318 p1=1 p2=978 p3=1
    WAIT #3: nam='db file sequential read' ela= 10292 p1=1 p2=318 p3=1
    FETCH #3:c=10000,e=21071,p=2,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=3017770393830
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=172 op='TABLE ACCESS FULL DUAL (cr=3 r=0 w=0 time=121 us)'
    QUERY
    ALTER SESSION SET EVENTS '10053 trace name context off'
    =====================
    PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017770394351 hv=3500836485 ad='3bed84c8'
    ALTER SESSION SET EVENTS '10053 trace name context off'
    END OF STMT
    PARSE #1:c=0,e=227,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017770394344
    BINDS #1:
    EXEC #1:c=0,e=177,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017770394624
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:36:13.139
    WAIT #1: nam='SQL*Net message from client' ela= 14951473 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=55 dep=0 uid=33 oct=42 lid=33 tim=3017785346905 err=911
    ALTER SESSION SET EVENT=¿10046 trace name context off¿
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2358 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:36:53.497
    WAIT #1: nam='SQL*Net message from client' ela= 39408861 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=56 dep=0 uid=33 oct=42 lid=33 tim=3017824759339 err=911
    ALTER SESSION SET EVENTS ¿10046 trace name context off¿
    WAIT #1: nam='SQL*Net break/reset to client' ela= 4 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2342 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:37:17.528
    WAIT #1: nam='SQL*Net message from client' ela= 23463963 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=57 dep=0 uid=33 oct=42 lid=33 tim=3017848226738 err=911
    ALTER SESSION SET EVENTS '10043 trace name context off';
    WAIT #1: nam='SQL*Net break/reset to client' ela= 1 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2305 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net message from client' ela= 9416071 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017857646552 hv=2635134026 ad='4b92b7e8'
    ALTER SESSION SET EVENTS '10043 trace name context off'
    END OF STMT
    PARSE #1:c=0,e=616,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017857646541
    BINDS #1:
    EXEC #1:c=0,e=285,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017857647009
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:58:46.112
    WAIT #1: nam='SQL*Net message from client' ela= 1248974802 p1=1413697536 p2=1 p3=0
    XCTEND rlbk=0, rd_only=1

  • Help with a union all statement

    Hello
    I am pulling a query much like this:
    (select ID, Created_timestamp from snapshot1
    where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
    and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
    UNION ALL
    (select ID, created_timestamp from snapshot2
    where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
    and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
    UNION ALL
    (select ID, created_timestamp from data_history
    where created_timestamp >= to_date ('8/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM')
    and created_timestamp < to_date('8/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'))
    Is there an easier way to handle created_timestamp?
    I would like to put it at the beginning so I only have to change it in one place.

    I don't understand.
    I try your with statement and get: "end_date" invalid identifier as an error
    I start my query out:
    WITH start_date as
    (select to_date ('08/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM') from dual),
    end_date as (select to_date ('08/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM) from dual)
    select sales.id, start_date as callstart, end_date as callend
    where sales.created_timestamp >= start_date
    and sales.created_timestamp < end_date
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with manufacturing>>>>>>>>>>>>>
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with engineering>>>>>>>>>>>>>
    and it still fails.

  • Concatenation and Union all

    Hi,
    From Oracle 9i performance guide:
    "Concatenation is useful for statements with different conditions combined with an OR clause"
    "If a query contains a WHERE clause with multiple conditions combined with OR operators, then the optimizer transforms it into an equivalent compound query that uses the UNION ALL set operator, if this makes the query execute more efficiently"
    Can anyone tell me when concatenation is better than union and vice versa?

    skde wrote:
    Hi,
    From Oracle 9i performance guide:
    "Concatenation is useful for statements with different conditions combined with an OR clause"
    "If a query contains a WHERE clause with multiple conditions combined with OR operators, then the optimizer transforms it into an equivalent compound query that uses the UNION ALL set operator, if this makes the query execute more efficiently"
    Can anyone tell me when concatenation is better than union and vice versa?Concatenation is not exactly the same as UNION ALL (the ALL is important, by the way), as it has to eliminate repetitions of data. You may rewrite an 'OR' query as a UNION ALL, concatenation is simply Oracle's strategy for doing this. There's an example on my blog which might help you understand the issues: http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
    +"I believe in evidence. I believe in observation, measurement, and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wilder and more ridiculous something is, however, the firmer and more solid the evidence will have to be."+
    Isaac Asimov                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Issue with union all in sql

    Hi All,
    I have a requirement as below.
    SELECT 'A' AS 'XXX' FROM DUAL
    UNION ALL
    SELECT 'B' AS 'XXX' FROM DUAL
    I need to check in such a way in my second sql query if 'B'='A' then i need to print 'A' else 'B' , means in my second query i need to compare the value of XXX with the first query value of XXX if it is same then i need to print first query's value of XXX or else need to print second queries XXX value.
    Please help me on this

    user13424229 wrote:
    Hi All,
    I have a requirement as below.
    SELECT 'A' AS 'XXX' FROM DUAL
    UNION ALL
    SELECT 'B' AS 'XXX' FROM DUAL
    I need to check in such a way in my second sql query if 'B'='A' then i need to print 'A' else 'B' , means in my second query i need to compare the value of XXX with the first query value of XXX if it is same then i need to print first query's value of XXX or else need to print second queries XXX value.
    Please help me on thisYour quesiton is not very clear, I would suggest you read {message:id=9360002}.
    If you are looking at a way to see the next or previous row from your current row then you can use LEAD or LAG analytical function. They are well documented. You can read all about it there.

  • Union All with Linked Servers - Works until loaded on to the report server then fails.

    Hi,
    On our production server I have 2 linked servers.  One that leads to ServiceNow via ODBC and one that leads to an HP Openview database.
    Testing these linked servers works fine.  I have a query that obtains info from each source and 'union all' together.  When i run this query in SQL Server management studio it works fine and I get info from both data sources union-ed together perfectly.
    I transfer this into Visual Studio and create a report, which again runs perfectly.
    I upload this report to the report server and try to run it and get the error: 
    An error has occurred during report processing. (rsProcessingAborted)
    Query execution failed for dataset 'Dataset1'. (rsErrorExecutingCommand)
    For more information about this error navigate to the report server on the local server machine, or enable remote errors
    When I rummage through the log files for the report server, I find very little helpful errors, basically this:
    ERROR: Throwing Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: , Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Query execution failed for dataset 'Dataset1'. ---> System.Data.SqlClient.SqlException: Cannot
    execute the query.
    I did a test where I created a copy of the report and ran only he Servicenow  section of the report and it works, then ran only the HP section of the report and it works.  It seems the UNION ALL is the problem somehow. 
    Anyone have any ideas??
    Thanks
    Kirsty

    Hi Kirsty,
    As you posted, this issue is caused by the security configuration of Linked Server.
    Generally, in a domain environment, we can specify a domain account as the stored credentials for the report, and then configure the Linked Server to "Be made using the login’s current security context".
    However,if we specify a SQL Server login as the stored credentials for the report, please set the Linked Server security to "By using this security context", and then providing the necessary credentials to authenticate at the linked server.
    Please also add the Reporting Services Security role to the Linked Server Remote Server Login Mappings.
    For more information about Creating Linked Servers, please refer to
    http://msdn.microsoft.com/en-us/library/ff772782.aspx
    About Security for Linked Servers, please refer to
    http://msdn.microsoft.com/en-us/library/ms175537.aspx
    Regards,
    Swallow

  • Re Creating  a chart getting an error with a 'Union All' statement

    Hi
    I have some data to chart with the following fields;
    Product , Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10.
    The PRODUCT field is text showing the numerous Product Names
    The Jul-08 & other month fields have numbers per product that is to be aggregated for that month & plotted on the line graph.
    My SQL to create the first point on the chart is as below;
    select null link, PRODUCT label, SUM(JUL-08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    GROUP by PRODUCT
    ORDER BY PRODUCT
    This works fine until I want add the second point of this line graph using a 'union all' join as follows;
    select null link, PRODUCT label, SUM(JUL_08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    UNION ALL
    select null link, PRODUCT label, SUM(AUG_08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    I can't work out how I can join the other months on the line graph in one series.
    The error is as follows;
    1 error has occurred
    Failed to parse SQL query:
    select null link, PRODUCT label, SUM(OCT_09) "NCDS - STD" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - STD' UNION ALL select null link, PRODUCT label, SUM(NOV_09) "NCDS - LOCAL" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - LOCAL'
    ORA-00937: not a single-group group function
    Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
    Can anyone assist?
    I want a continuous Line Graph that shows all the months from Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10 for the same product.
    I will then add other series for the other products, Thanks

    OK, I thought each month would be separated by the different months in each selct subquery, but I see what you mean.
    I'm creating a line graph for various PRODUCTS that has a numeric value for each month, from JUL_08 ..... for a number of months.
    I want a LINE graph that shows the different totals each month for that PRODUCT.
    The error advises that there are more values in the SELECT statement than the expected and to use Use the following syntax:
    SELECT LINK, LABEL, VALUE
    FROM ...
    I then went on to use the '[ ]' brackets to separate data but this didn't fix the problem.
    I've changed the script to suit as per your 'PERIOD' addition but now have the error as per below;
    error script
    1 error has occurred
    Invalid chart query: SELECT null link, PRODUCT label, PERIOD, SUM(ABC) FROM (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT) GROUP BY link, PRODUCT, PERIOD
    Use the following syntax:
    SELECT LINK, LABEL, VALUE
    FROM ...
    Or use the following syntax for a query returning multiple series:
    SELECT LINK, LABEL, VALUE1 [, VALUE2 [, VALUE3...]]
    FROM ...
    LINK URL
    LABEL Text that displays along a chart axis.
    VALUE1, VALUE2, VALUE3... Numeric columns that define the data values.
    Note: The series names for Column and Line charts are derived from the column aliases used in the query.
    My script amended;
    SELECT null link, PRODUCT label, PERIOD, SUM(ABC)
    FROM
    (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT
    UNION ALL
    SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT
    UNION ALL
    SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT)
    GROUP BY link, PRODUCT, PERIOD

  • How can I join/Full outer join two different columns instead of union all?

    Hi,
    I have a scenario as the following:
    I am performing set operations using obiee 11g where I want to take values from two different criteria. Howwver, I dont want union to take place, instead i want join to take place to see all the columns in the output.
    For that, I tried changing the sql in advanced tab and tried to put full outer join instead of union all but its not allowing me to change.
    How can I achieve it? please help.
    Thanks.

    Hi,
    My problem is that I am unable to modify the sql in advanced tab. Probably due to some security reason,it's restricting me to change.
    Can you suggest me a way to change it?
    Thanks..

  • Using order by in Union ALL

    hi Following is my query and am unable to accomplish my order by statement in Union All . please help me in this.
    <code>
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    a.lot_id,
    b.comment_text "Comments"
    FROM clem_audit_trail b,lot a, users u
    WHERE a.lot_id = b.lot_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND a.lot_id in (select lot_id from request_lot where request_id = 51914)
    AND col_name IN
    ('Interim Release Date',
    'Final Disposition Date',
    'On Time Disposition',
    'Intended Use',
    'REJECTS_YN',
    '# of QARs',
    '# of Quality Events',
    '# of LIRs',
    '# of Change Controls',
    '# of Batch Records',
    '# of GMP Batch Records',
    'EXPLANATION',
    'QA Notes',
    'GDMS_LINK')
    AND UPPER (table_name) IN('LOT') order by b.last_update_date
    UNION ALL
    SELECT b.audit_trail_id,
    TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    (u.last_name || ', ' || u.first_name || ' ' || u.mi) "By",
    b.col_name "Field",
    b.new_value "New Value",b.previous_value "Old Value",
    r.request_id,
    b.comment_text "Comments"
    FROM clem b,request r, users u
    WHERE r.request_id = b.request_id(+)
    AND u.user_id(+) = b.last_update_user_id
    AND r.request_id = 51914
    AND UPPER (table_name) IN ('REQUEST') AND
    b.col_name IN ('Partial Release',
    'All QP Docs in GDMS',
    'Number of Batch Records',
    'Request',
    'QP Issues',
    'Snag Comments',
    'Responsible Group',
    'Reason Late',
    'Study Impact',
    'Other Details',
    'Request Status',
    'QP Link to GDMS'
    ) order by b.last_update_date
    </code>
    If i execute individually it works fine, if i use union all it throughs error for me.
    Any suggestion...

    Hi,
    In a set operation (such as UNION) table aliases (such as b.) only have meaning within the branch in which they are defined. The ORDER BY clause is not part of any 1 branch, so a table alias can't be used there.
    In most cases, you can use a column name (or alias) from the first branch, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  "Revision Date"
    ;and you can always order by column number, like this:
    SELECT    b.audit_trail_id,
              TO_CHAR (b.last_update_date, 'DD-Mon-YYYY') "Revision Date",
    order by  2
    ;In this case, however, there's an extra problem. You're transforming the DATE to a string in the SELECT clause. The string is all that's available in the ORDER BY clause, and the string '19-NOV-2012' comes after the string '01-JAN-2015', because the character '1' comes after '0'. Perhaps the simplest solution is to have your front end, and not the query, format the dates. In SQL*Plus, you can do this:
    ALTER SESSION  SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
    SELECT    b.audit_trail_id,
              b.last_update_date    AS "Revision Date",
    order by  2
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

Maybe you are looking for