Why tree query can't take where clause

I build a tree struncture without where clause , it is fine, but When I tried to add a where clause, I get error, (Warning: Tree root ID "1" not found. ). Does anybody know why?
Here is my SQL
select "ID" id,
"PID" pid,
"NAME" name,
"LINK" link
from CAPACITY_TREE
where branch='CAP'
order by 3

Hi,
I'm having a similar problem in APEX 3.01. If you try to create a try using the following query you get the: Warning: Tree root ID "7839" not found error, where 7839 is the "KING" id empno
WITH x AS
     (SELECT "EMPNO" ID,
             "MGR" pid,
             "ENAME" NAME,
             NULL LINK,
             NULL a1,
             NULL a2
      FROM   "EMP"
      where ename = 'JONES')
SELECT x.id, x.pid, x.name, x.link, x.a1, x.a2
FROM   xAny ideas as to why we can't put a where clause in a tree?

Similar Messages

  • Can we use where clause in Update on Merge statement?

    Hi All,
    I tried to execute the following Merge Query:
    When this query is executed without ‘Where clause’ in Update statement its working fine. When executed with ‘Where clause’ it throwing the following error:
    ORA-00905: missing keyword.
    Following is the sample query which I tried to execute:
    MERGE INTO TABLE_NAME
    USING (SELECT COLUMN FORM TABLES)
    ON (CONDITION)
    WHEN MATCHED THEN
    UPDATE SET
         COLUMN UPATES
    WHERE CONDITION -- Can we use where clause here?
    WHEN NOT MATCHED THEN
    INSERT
    INSERT VALUES;
    Can some one help on this?
    Thanks in advance.
    Darius

    Yes:
    SQL> drop table emp1;
    Table dropped.
    SQL> create table emp1 as select * from emp where deptno = 30;
    Table created.
    SQL> update emp1 set sal = sal*2;
    6 rows updated.
    SQL> commit;
    Commit complete.
    SQL> select ename,sal from emp1;
    ENAME             SAL
    ALLEN            3200
    WARD             2500
    MARTIN           2500
    BLAKE            5700
    TURNER           3000
    JAMES            1900
    6 rows selected.
    SQL> MERGE INTO emp1
      2  USING(select * from emp) emp
      3  ON (emp1.empno = emp.empno)
      4  WHEN MATCHED THEN
      5  UPDATE SET sal = emp.sal WHERE ename = 'TURNER'
      6  WHEN NOT MATCHED THEN
      7  INSERT(ename,sal) VALUES(emp.ename,emp.sal);
    9 rows merged.
    SQL> select ename,sal from emp1;
    ENAME             SAL
    ALLEN            3200
    WARD             2500
    MARTIN           2500
    BLAKE            5700
    TURNER 1500
    JAMES            1900
    SMITH             800
    JONES            2975
    CLARK            2450
    SCOTT            3000
    KING             5000
    ENAME             SAL
    ADAMS            1100
    FORD             3000
    MILLER           1300
    14 rows selected.
    SQL> SY.

  • Why I cannot use RowID in where clause but can use it in order by clause

    I am on SQL Server 2008.
    1. If I use
    SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
      order by RowID
    Statement works
    But
    2. If I use
    SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
      where  RowID > 10000
    I get error, RowID is an invalid column Name why? How to correct query 2.

    This is due to the logical evaluation order of a SELECT statement. Logically, a SELECT statement is computed in the order:
    FROM (which includes JOIN)
    WHERE
    GROUP BY
    HAVING
    SELECT
    ORDER BY
    OFFSET
    Thus, you can use what is defined in the SELECT list in the ORDER BY clause, but not in the WHERE clause.
    In the case of row_number(), this has immediate repurcussions. row_number() is computed from the rows as they arrive the SELECT clause, and if you then you would filter on the value in the WHERE clause you would be going round in circles.
    To do what you are looking for, you use a nested table, for instance with a CTE:
    WITH numbering AS (
       SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
    SELECT *
    FROM   numbering
    WHERE  RowID > 10000
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Using Parameters in SQL-Query not only in where clauses

    Hi,
    I try to use Publisher parameters in the SQL Query from a Data Set.
    All of them have default values.
    So far, this is no problem, unless I try to use such a parameter value as an ordinary attribute value:
    >
    select
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."BETR_TEIL"
                                            else :pv_some_Text end                                                                  as Betr_Teil,
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM"
                                            else :pv_some_Text end                                                        as Suva_Nr,
         case when (:pv_Group = 'no') then "DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH"
                                            else sum("DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") end      as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in (:pv_nim100)
         fetch first 65001 rows ONLY
    >
    The parameters 'pv_Group' and 'pv_nim100' are working fine. (when or where clauses)
    The parameter 'pv_some_Text' unfortunately not. (simple literals)
    When I try to validate the above SQL, I get the following Error:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46033] Datatype: 25 is not supported.
    </font>
    After use a cast function:
    >
    else CAST(:pv_some_Text AS CHARACTER)
    >
    I get this ERROR:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 19002] Incorrect use of parameters. The parameters used in CAST cannot be resolved without ambiguity.
    </font>
    We use OBIEE 11.1.1.6.4 on a Win64-System.
    Thank's for any help.

    Hi Alex,
    let's leave away any unnecessary details.
    This is the SQL, inserted in the window 'Edit Data Set' of BIP Data Model:
    >
    select
         '--1'     as Betr_Teil,
         '--2'      as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    Everything is fine when I click OK, the script goes back to the metadata.
    Let's try this script with bind values in ORACLE SQL Developer.
    This SQL is the physical part, found in the OBIEE-Log (Log level 5), except the bind values. Therefore we find, in the where clause, the join. In the logical sql, we don't have to join, because it's handled in the Common Enterprise Information Model (CEIM)
    >
    with
    sawith0 as
    select
    sum(t39617.ris_vollbesch) as c1
    from
    dm15d_betriebsteil t39455,
    dm15k_ris_fakten_pro_btt_jhr t39617
    where
    t39455.id_betriebsteil = t39617.id_betriebsteil
    and t39455.suva_nr_form = '122-4.4'
    select
    d1.c1 as c1,
    d1.c2 as c2,
    d1.c3 as c3
    from
    select
    :pv_some_text as c1,
    :pv_some_text as c2,
    sum(d1.c1) as c3
    from
    sawith0 d1
    d1
    where
    rownum <= 65001
    >
    This SQL works fine, even with bind values for 'pv_some_text'.
    But, when using the following SQL in the BIP Data Model:
    >
    select
         :pv_Text as Betr_Teil,
         :pv_Text as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    The following ERROR occurs:
    <font color="red">java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46008] Internal error: File server\Query\Optimizer\ServiceInterfaceMgr\Utility\Src\SQOIUTypeVisitor.cpp, line 643.</font>
    In my opinion, either I use a wrong syntax, or BIP has a problem with parsing the script.
    Thank you for your most welcome help.

  • Query API to build where clause

    Hi All ,
               Is there any API in the Netweaver Layer through which i can build open sql where clause by just passing the selection parameter table . I have tried using the cl_rsmds_*  api but it doesnot returns correct result in some senario.
    With regards,
    Saurabh Kumar Pandey .

    SELECT *
    FROM   table_name pr
    WHERE ( (pr.status_cid IN (5,86) OR ( pr.org_unit_sid = 3001 AND pr.status_cid IN (25))
    {code}
    PS: Kindly mark the answers to your post as helpfull/correct if you are satisfied
    Edited by: Himanshu Binjola on Apr 23, 2012 9:34 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Bad query plan for self-referencing CTE view query and variable in WHERE clause. Is there way out or this is SQL Server defect?

    Please help. Thank you for your time and expertise.
    Prerequisites: sql query needs to be a view. Real view is more than recursion. It computes location path,  is used in JOINs and returns this path.
    Problem: no matter what I tried, sql server does not produce 'index seek' when using variable but does with literal.
    See full reproduction code below.
    I expect that query SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID will seek UNIQUE index but it does not.
    I tried these:
    1. Changing UX and/or PK to be CLUSTERED.
    2. query OPTION(RECOMPILE)
    3. FORCESEEK on view
    4. SQL Server 2012/2014
    5. Wrap it into function and CROSS APPLY. On large outer number of rows this just dies, no solution
    but to no avail. This smells like a bug in SQL Server. I am seeking your confirmation.
    I am thinking it is a bug as variable value is high-cardinality, 1, and query is against unique key. This must produce single seek, depending if clustered or nonclustred index is unique
    Thanks
    Vladimir
    use tempdb
    BEGIN TRAN
    -- setup definition
    CREATE TABLE dbo.LocationHierarchy(
    lcID int NOT NULL ,
    lcHID hierarchyid NOT NULL,
    lcCode nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    lcHIDParent AS lcHID.GetAncestor(1) PERSISTED,
    CONSTRAINT PK_LocationHierarchy_lcID PRIMARY KEY NONCLUSTERED (lcID ASC),
    CONSTRAINT UX_LocationHierarchy_pltID_lcHID UNIQUE CLUSTERED (lcHID ASC)
    -- add some data
    INSERT INTO dbo.LocationHierarchy
    VALUES
    (1, '/', 'A')
    ,(2, '/1/', 'B')
    ,(3, '/1/1/', 'C')
    ,(4, '/1/1/1/', 'D')
    --DROP VIEW dbo.vwLocationCodes
    GO
    CREATE VIEW dbo.vwLocationCodes
    AS
    WITH ru AS
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.lcHID
    ,CAST('/' + lh.lcCode + '/' as varchar(8000)) as LocationPath
    -- to support recursion
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    UNION ALL
    SELECT
    ru.lcID
    ,ru.lcCode
    ,ru.lcHID
    ,CAST('/' + lh.lcCode + ru.LocationPath as varchar(8000)) as LocationPath
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    JOIN ru ON ru.lcHIDParent = lh.lcHID
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.LocationPath
    ,lh.lcHID
    FROM ru lh
    WHERE lh.lcHIDParent IS NULL
    GO
    -- get data via view
    SELECT
    CONCAT(SPACE(l.lcHID.GetLevel() * 4), lcCode) as LocationIndented
    FROM dbo.vwLocationCodes l
    ORDER BY lcHID
    GO
    SET SHOWPLAN_XML ON
    GO
    DECLARE @lcID int = 2
    -- I believe this produces bad plan and is defect in SQL Server optimizer.
    -- variable value cardinality is 1 and SQL Server should know that. Optiomal plan is to do index seek with key lookup.
    -- This does not happen.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID -- bad plan
    -- this is a plan I expect.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = 2 -- good plan
    -- I reviewed these but I need a view here, can't be SP
    -- http://sqlblogcasts.com/blogs/tonyrogerson/archive/2008/05/17/non-recursive-common-table-expressions-performance-sucks-1-cte-self-join-cte-sub-query-inline-expansion.aspx
    -- http://social.msdn.microsoft.com/Forums/sqlserver/en-US/22d2d580-0ff8-4a9b-b0d0-e6a8345062df/issue-with-select-using-a-recursive-cte-and-parameterizing-the-query?forum=transactsql
    GO
    SET SHOWPLAN_XML OFF
    GO
    ROLLBACK
    Vladimir Moldovanenko

    Here is more... note that I am creating table Items and these can be in Locations.
    I am trying LEFT JOIN and OUTER APLLY to 'bend' query into NESTED LOOP and SEEK. There has to be nested loop, 2 rows against 4. But SQL Server fails to generate optimal plan with SEEK. Even RECOMPILE does not help
    use tempdb
    BEGIN TRAN
    -- setup definition
    CREATE TABLE dbo.LocationHierarchy(
    lcID int NOT NULL ,
    lcHID hierarchyid NOT NULL,
    lcCode nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    lcHIDParent AS lcHID.GetAncestor(1) PERSISTED,
    CONSTRAINT PK_LocationHierarchy_lcID PRIMARY KEY NONCLUSTERED (lcID ASC),
    CONSTRAINT UX_LocationHierarchy_pltID_lcHID UNIQUE CLUSTERED (lcHID ASC)
    -- add some data
    INSERT INTO dbo.LocationHierarchy
    VALUES
    (1, '/', 'A')
    ,(2, '/1/', 'B')
    ,(3, '/1/1/', 'C')
    ,(4, '/1/1/1/', 'D')
    --DROP VIEW dbo.vwLocationCodes
    GO
    --DECLARE @Count int = 10;
    --WITH L0 AS (SELECT N FROM (VALUES(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) N (N))-- 10 rows
    --,L1 AS (SELECT n1.N FROM L0 n1 CROSS JOIN L0 n2) -- 100 rows
    --,L2 AS (SELECT n1.N FROM L1 n1 CROSS JOIN L1 n2) -- 10,000 rows
    --,L3 AS (SELECT n1.N FROM L2 n1 CROSS JOIN L2 n2) -- 100,000,000 rows
    --,x AS
    -- SELECT TOP (ISNULL(@Count, 0))
    -- ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) as Number
    -- FROM L3 n1
    --SELECT Number as itmID, NTILE(4)OVER(ORDER BY Number) as lcID
    --INTO dbo.Items
    --FROM x
    ----ORDER BY n1.N
    --ALTER TABLE dbo.Items ALTER COLUMN itmID INT NOT NULL
    --ALTER TABLE dbo.Items ADD CONSTRAINT PK PRIMARY KEY CLUSTERED (itmID)
    CREATE TABLE dbo.Items (itmID int NOT NULL PRIMARY KEY, lcID int NOT NULL)
    INSERT INTO dbo.items
    VALUES(1, 1)
    ,(2, 3)
    GO
    CREATE VIEW dbo.vwLocationCodes
    AS
    WITH ru AS
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.lcHID
    ,CAST('/' + lh.lcCode + '/' as varchar(8000)) as LocationPath
    -- to support recursion
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    UNION ALL
    SELECT
    ru.lcID
    ,ru.lcCode
    ,ru.lcHID
    ,CAST('/' + lh.lcCode + ru.LocationPath as varchar(8000)) as LocationPath
    ,lh.lcHIDParent
    FROM dbo.LocationHierarchy lh
    JOIN ru ON ru.lcHIDParent = lh.lcHID
    SELECT
    lh.lcID
    ,lh.lcCode
    ,lh.LocationPath
    ,lh.lcHID
    FROM ru lh
    WHERE lh.lcHIDParent IS NULL
    GO
    -- get data via view
    SELECT
    CONCAT(SPACE(l.lcHID.GetLevel() * 4), lcCode) as LocationIndented
    FROM dbo.vwLocationCodes l
    ORDER BY lcHID
    GO
    --SET SHOWPLAN_XML ON
    GO
    DECLARE @lcID int = 2
    -- I believe this produces bad plan and is defect in SQL Server optimizer.
    -- variable value cardinality is 1 and SQL Server should know that. Optiomal plan is to do index seek with key lookup.
    -- This does not happen.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = @lcID-- OPTION(RECOMPILE) -- bad plan
    -- this is a plan I expect.
    SELECT lcCode FROM dbo.vwLocationCodes l WHERE l.lcID = 2 -- good plan
    SELECT *
    FROM dbo.Items itm
    LEFT JOIN dbo.vwLocationCodes l ON l.lcID = itm.lcID
    OPTION(RECOMPILE)
    SELECT *
    FROM dbo.Items itm
    OUTER APPLY
    SELECT *
    FROM dbo.vwLocationCodes l
    WHERE l.lcID = itm.lcID
    ) l
    -- I reviewed these but I need a view here, can't be SP
    -- http://sqlblogcasts.com/blogs/tonyrogerson/archive/2008/05/17/non-recursive-common-table-expressions-performance-sucks-1-cte-self-join-cte-sub-query-inline-expansion.aspx
    -- http://social.msdn.microsoft.com/Forums/sqlserver/en-US/22d2d580-0ff8-4a9b-b0d0-e6a8345062df/issue-with-select-using-a-recursive-cte-and-parameterizing-the-query?forum=transactsql
    GO
    --SET SHOWPLAN_XML OFF
    GO
    ROLLBACK
    Vladimir Moldovanenko

  • Query with date in where clause

    hi,
    i have build a view with join conditions from 8 tables. the data from this view is more then 100,000
    when i run the query with different clause its work with some seconds. but when i put date column in where cluase it sleeps.
    eg..
    where unit_id = 4 and t_id = 's09' and vb like '%amb%'
    works fine.
    where unit_id = 4 and t_id = 's09' and vb like '%amb%' and date between dt1 and dt2
    now sleep
    please ......give me some suggestions

    hi i have done the explain plan
    the result is
    Operation Object
    SELECT STATEMENT ()
    NESTED LOOPS ()
    NESTED LOOPS ()
    HASH JOIN ()
    HASH JOIN ()
    TABLE ACCESS (FULL) PR_PO_MST
    TABLE ACCESS (FULL) PR_SUPPLIER
    TABLE ACCESS (FULL) PR_PO_DTL
    TABLE ACCESS (BY INDEX ROWID) INDENT_MST
    INDEX (RANGE SCAN) ST_IND_MST_IDX
    TABLE ACCESS (BY INDEX ROWID) ST_ITEM
    Operation Object
    INDEX (UNIQUE SCAN) PK_ST_ITEM
    now wot do do????

  • Can we use where clause in for-each: tag_name ?- urgent

    Hi All,
    I am using templated builder 5.5
    1)2 G_LINE Repeating Groups will exist for every Invoice Line. Each will have an INVOICE_LINE_TYPE element, set as either ‘Line’ or ‘Tax’. Both of the G_LINE groups will be used to create the Invoice Lines output for a consolidated invoice.
    2)<?for-each:G_LINES WHERE ORDER_LINE_TYPE = ‘LINE’?>
    Data to be displayed...
    <?end FOR-EACH?>
    Repeating group to display all of the invoice lines associated with a particular consolidated invoice.
    The XML Element to base repeating group on is G_LINES
    Is it possible to use the above tags, if yes how an d if no, will this be suppoerted in 5.6.1 version?
    Thanks in advance

    Hi
    You'll have to add the code but you can use XPATH to limit the data to the LINE data:
    <?for-each:G_LINES[ORDER_LINE_TYPE = ‘LINE’]?>
    this limits the rows to just those that satisfy the condition.
    If you want to show the LINE and TAX data you would be better to loop over the G_LINES and then use an 'if' statement across the group. So you would have a two row table to hold the LINE and TAX data and then use a if@row statement to filter on LINE and TAX data.
    Regards, Tim

  • SQL QUERY How to write a sql query with a complex where clause.

    I would like to get a list of all my invoices from the past year plus any open invoices that are more than a year old.
    I don't want any overlapping rows.
    Debra has a question

    Debra,
    Sorry but you have posted to a forum that deals exclusively with questions/issues about customizing and programming Microsoft Project, a planning and scheduling application. I suggest you delete this post and find a more appropriate forum.
    John

  • Response time of query utterly upside down because of small where clause change

    Hello,
    I'm wondering why a small change on a where clause in a query has a dramatic impact on its response time.
    Here is the query, with its plan and a few details:
    select * from (
    SELECT xyz_id, time_oper, ...
         FROM (SELECT 
                        d.xyz_id xyz_id,
                        TO_CHAR (di.time_operation, 'DD/MM/YYYY') time_oper,
                        di.time_operation time_operation,
                        UPPER (d.delivery_name || ' ' || d.delivery_firstname) custname,
                        d.ticket_language ticket_language, d.payed,
                        dsum.delivery_mode delivery_mode,
                        d.station_delivery station_delivery,
                        d.total_price total_price, d.crm_cust_id custid,
                        d.bene_cust_id person_id, d.xyz_num, dpe.ers_pnr ers_pnr,
                        d.delivery_name,
                        TO_CHAR (dsum.first_travel_date, 'DD/MM/YYYY') first_traveldate,
                        d.crm_company custtype, UPPER (d.client_name) partyname,
                        getremark(d.xyz_num) remark,
                        d.client_app, di.work_unit, di.account_unit,
                        di.distrib_code,
                        UPPER (d.crm_name || ' ' || d.crm_firstname) crm_custname,
                       getspecialproduct(di.xyz_id) specialproduct
                   FROM xyz d, xyz_info di, xyz_pnr_ers dpe, xyz_summary dsum
                  WHERE d.cancel_state = 'N'
                 -- AND d.payed = 'N'
                    AND dsum.delivery_mode NOT IN ('DD')
                    AND dsum.payment_method NOT IN ('AC', 'AG')
                    AND d.xyz_blocked IS NULL
                    AND di.xyz_id = d.xyz_id
                    AND di.operation = 'CREATE'
                    AND dpe.xyz_id(+) = d.xyz_id
                    AND EXISTS (SELECT 1
                                  FROM xyz_ticket dt
                                 WHERE dt.xyz_id = d.xyz_id)
                    AND dsum.xyz_id = di.xyz_id
               ORDER BY di.time_operation DESC)
        WHERE ROWNUM < 1002
    ) view
    WHERE view.DISTRIB_CODE in ('NS') AND view.TIME_OPERATION > TO_DATE('20/5/2013', 'dd/MM/yyyy')
    plan with "d.payed = 'N'" (no rows, *extremely* slow):
    | Id  | Operation                          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                  |  1001 |  4166K| 39354   (1)| 00:02:59 |
    |*  1 |  VIEW                              |                  |  1001 |  4166K| 39354   (1)| 00:02:59 |
    |*  2 |   COUNT STOPKEY                    |                  |       |       |            |          |
    |   3 |    VIEW                            |                  |  1001 |  4166K| 39354   (1)| 00:02:59 |
    |   4 |     NESTED LOOPS OUTER             |                  |  1001 |   130K| 39354   (1)| 00:02:59 |
    |   5 |      NESTED LOOPS SEMI             |                  |   970 |   111K| 36747   (1)| 00:02:47 |
    |   6 |       NESTED LOOPS                 |                  |   970 |   104K| 34803   (1)| 00:02:39 |
    |   7 |        NESTED LOOPS                |                  |   970 | 54320 | 32857   (1)| 00:02:30 |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| XYZ_INFO         |    19M|   704M| 28886   (1)| 00:02:12 |
    |   9 |          INDEX FULL SCAN DESCENDING| DNIN_IDX_NI5     | 36967 |       |   296   (2)| 00:00:02 |
    |* 10 |         TABLE ACCESS BY INDEX ROWID| XYZ_SUMMARY      |     1 |    19 |     2   (0)| 00:00:01 |
    |* 11 |          INDEX UNIQUE SCAN         | SB11_DSMM_XYZ_UK |     1 |       |     1   (0)| 00:00:01 |
    |* 12 |        TABLE ACCESS BY INDEX ROWID | XYZ              |     1 |    54 |     2   (0)| 00:00:01 |
    |* 13 |         INDEX UNIQUE SCAN          | XYZ_PK           |     1 |       |     1   (0)| 00:00:01 |
    |* 14 |       INDEX RANGE SCAN             | DNTI_NI1         |    32M|   249M|     2   (0)| 00:00:01 |
    |  15 |      TABLE ACCESS BY INDEX ROWID   | XYZ_PNR_ERS      |     1 |    15 |     4   (0)| 00:00:01 |
    |* 16 |       INDEX RANGE SCAN             | DNPE_XYZ         |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
      1 - filter("DISTRIB_CODE"='NS' AND "TIME_OPERATION">TO_DATE(' 2013-05-20', 'syyyy-mm-dd'))
      2 - filter(ROWNUM<1002)
      8 - filter("DI"."OPERATION"='CREATE')
    10 - filter("DSUM"."DELIVERY_MODE"<>'DD' AND "DSUM"."PAYMENT_METHOD"<>'AC' AND "DSUM"."PAYMENT_METHOD"<>'AG')
    11 - access("DSUM"."XYZ_ID"="DI"."XYZ_ID")
    12 - filter("D"."PAYED"='N' AND "D"."XYZ_BLOCKED" IS NULL AND "D"."CANCEL_STATE"='N')
                  ^^^^^^^^^^^^^^
    13 - access("DI"."XYZ_ID"="D"."XYZ_ID")
    14 - access("DT"."XYZ_ID"="D"."XYZ_ID")
    16 - access("DPE"."XYZ_ID"(+)="D"."XYZ_ID")
    plan with "d.payed = 'N'" (+/- 450 rows, less than two minutes):
    | Id  | Operation                          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                  |  1001 |  4166K| 58604   (1)| 00:04:27 |
    |*  1 |  VIEW                              |                  |  1001 |  4166K| 58604   (1)| 00:04:27 |
    |*  2 |   COUNT STOPKEY                    |                  |       |       |            |          |
    |   3 |    VIEW                            |                  |  1002 |  4170K| 58604   (1)| 00:04:27 |
    |   4 |     NESTED LOOPS OUTER             |                  |  1002 |   130K| 58604   (1)| 00:04:27 |
    |   5 |      NESTED LOOPS SEMI             |                  |  1002 |   115K| 55911   (1)| 00:04:14 |
    |   6 |       NESTED LOOPS                 |                  |  1476 |   158K| 52952   (1)| 00:04:01 |
    |   7 |        NESTED LOOPS                |                  |  1476 | 82656 | 49992   (1)| 00:03:48 |
    |*  8 |         TABLE ACCESS BY INDEX ROWID| XYZ_INFO         |    19M|   704M| 43948   (1)| 00:03:20 |
    |   9 |          INDEX FULL SCAN DESCENDING| DNIN_IDX_NI5     | 56244 |       |   449   (1)| 00:00:03 |
    |* 10 |         TABLE ACCESS BY INDEX ROWID| XYZ_SUMMARY      |     1 |    19 |     2   (0)| 00:00:01 |
    |* 11 |          INDEX UNIQUE SCAN         | AAAA_DSMM_XYZ_UK |     1 |       |     1   (0)| 00:00:01 |
    |* 12 |        TABLE ACCESS BY INDEX ROWID | XYZ              |     1 |    54 |     2   (0)| 00:00:01 |
    |* 13 |         INDEX UNIQUE SCAN          | XYZ_PK           |     1 |       |     1   (0)| 00:00:01 |
    |* 14 |       INDEX RANGE SCAN             | DNTI_NI1         |    22M|   168M|     2   (0)| 00:00:01 |
    |  15 |      TABLE ACCESS BY INDEX ROWID   | XYZ_PNR_ERS      |     1 |    15 |     4   (0)| 00:00:01 |
    |* 16 |       INDEX RANGE SCAN             | DNPE_XYZ         |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("DISTRIB_CODE"='NS' AND "TIME_OPERATION">TO_DATE(' 2013-05-20', 'syyyy-mm-dd'))
       2 - filter(ROWNUM<1002)
       8 - filter("DI"."OPERATION"='CREATE')
      10 - filter("DSUM"."DELIVERY_MODE"<>'DD' AND "DSUM"."PAYMENT_METHOD"<>'AC' AND "DSUM"."PAYMENT_METHOD"<>'AG')
      11 - access("DSUM"."XYZ_ID"="DI"."XYZ_ID")
      12 - filter("D"."XYZ_BLOCKED" IS NULL AND "D"."CANCEL_STATE"='N')
      13 - access("DI"."XYZ_ID"="D"."XYZ_ID")
      14 - access("DT"."XYZ_ID"="D"."XYZ_ID")
      16 - access("DPE"."XYZ_ID"(+)="D"."XYZ_ID")
    XYZ.PAYED values breakdown:
    P   COUNT(1)
    Y   12202716
    N    9430207
    tables nb of records:
    TABLE_NAME           NUM_ROWS
    XYZ                  21606776
    XYZ_INFO            186301951
    XYZ_PNR_ERS           9716471
    XYZ_SUMMARY          21616607
    Everything that comes inside the "select * from(...) view" parentheses is defined in a view. We've noticed that the line "AND d.payed = 'N'" (commented above) is the guilty clause: the query takes one or two seconds to return between 400 and 500 rows if this line is removed, when included in the query, the response time then switches to *hours* -sic !- but then the result set is empty (no rows returned). The plan is exactly the same whether this "d.payed = 'N'" is added or removed, I mean the nb of steps, access paths, join order etc., only the rows/bytes/cost columns values change, as you can see.
    We've found no other way of solving this perf issue but by taking out this "d.payed = 'N'" condition and setting it outside the view along with view.DISTRIB_CODE and view.TIME_OPERATION.
    But we would like to understand why such a small change on the XYZ.PAYED column turns everything upside down that much, and we'd like to be able to tell the optimizer to perform this check on payed = 'N' by itself in the end, just like we did, through the use of a hint if possible...
    Anybody ever encountered such a behaviour before ? Do you have any advice regarding the use of a hint to reach the same response time as that we've got by setting the payed = N condition outside of the view definition ??
    Thanks a lot in advance.
    Regards,
    Seb

    I am really sorry I couldn't get back earlier to this forum...
    Thanks to you all for your answers.
    First I'd just like to correct a small mistake I made, when writing
    "the query takes one or two seconds": I meant one or 2 *minutes*. Sorry.
    > What table/columns are indexed by "DNTI_NI1"?
    aaaa.dnti_ni1 is an index ON aaaa.xyz_ticket(xyz_id, ticket_status)
    > And what are the indexes on xyz table?
    Too many:
    XYZ_ARCHIV_STATE_IND           ARCHIVE_STATE
    XYZ_BENE_CUST_ID_IND           BENE_CUST_ID
    XYZ_BENE_TTL_IND               BENE_TTL
    XYZ_CANCEL_STATE_IND           CANCEL_STATE
    XYZ_CLIENT_APP_NI              CLIENT_APP
    XYZ_CRM_CUST_ID_IND            CRM_CUST_ID
    XYZ_DELIVE_MODE_IND            DELIVERY_MODE
    XYZ_DELIV_BLOCK_IND            DELIVERY_BLOCKED
    XYZ_DELIV_STATE_IND            DELIVERY_STATE
    XYZ_XYZ_BLOCKED                XYZ_BLOCKED
    XYZ_FIRST_TRAVELDATE_IND       FIRST_TRAVELDATE
    XYZ_MASTER_XYZ_IND             MASTER_XYZ_ID
    XYZ_ORG_ID_NI                  ORG_ID
    XYZ_PAYMT_STATE_IND            PAYMENT_STATE
    XYZ_PK                         XYZ_ID
    XYZ_TO_PO_IDX                  TO_PO
    XYZ_UK                         XYZ_NUM
    For ex. XYZ_CANCEL_STATE_IND on CANCEL_STATE seems superfluous to me, as the column may only contain Y or N (or be null)...
    > Have you traced both cases to compare statistics? What differences did it reveal?
    Yes but it only shows more of *everything* (more tables blocks accessed, the same
    for indexes blocks, for almost all objects involved) for the slowest query !
    Greping WAIT on the two trc files made for every statement and counting the
    object IDs access show that the quicker query requires much less I/Os; the
    slowest one overall needs much more blocks to be read (except for the indexes
    DNSG_NI1 or DNPE_XYZ for example). Below I replaced obj# with the table/index
    name, the first column is the figure showing how many times the object was
    accessed in the 10053 file (I ctrl-C'ed my second execution ofr course, the
    figures should be much higher !!):
    [login.hostname] ? grep WAIT OM-quick.trc|...|sort|uniq -c
        335 XYZ_SUMMARY
      20816 AAAA_DSMM_XYZ_UK (index on xyz_summary.xyz_id)
        192 XYZ
       4804 XYZ_INFO
        246 XYZ_SEGMENT
          6 XYZ_REMARKS
         63 XYZ_PNR_ERS
        719 XYZ_PK           (index on xyz.xyz_id)
       2182 DNIN_IDX_NI5     (index on xyz.xyz_id)
        877 DNSG_NI1         (index on xyz_segment.xyz_id, segment_status)
        980 DNTI_NI1         (index on xyz_ticket.xyz_id, ticket_status)
        850 DNPE_XYZ         (index on xyz_pnr_ers.xyz_id)
    [login.hostname] ? grep WAIT OM-slow.trc|...|sort|uniq -c
       1733 XYZ_SUMMARY
      38225 AAAA_DSMM_XYZ_UK  (index on xyz_summary.xyz_id)
       4359 XYZ
      12536 XYZ_INFO
         65 XYZ_SEGMENT
         17 XYZ_REMARKS
         20 XYZ_PNR_ERS
       8598 XYZ_PK
       7406 DNIN_IDX_NI5
         29 DNSG_NI1
       2475 DNTI_NI1
         27 DNPE_XYZ
    The overwhelmingly dominant wait event is by far 'db file sequential read':
    [login.hostname] ? grep WAIT OM-*elect.txt|cut -d"'" -f2|sort |uniq -c
         36 SQL*Net message from client
         38 SQL*Net message to client
    107647 db file sequential read
          1 latch free
          1 latch: object queue header operation
          3 latch: session allocation
    > It will be worth knowing the estimations...
    It show the same plan with a higher cost when PAYED = N is added:
    SQL> select * from sb11.dnr d
      2* where d.dnr_blocked IS NULL and d.cancel_state = 'N'
    SQL> /
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                      |  1002 |   166K|    40   (3)| 00:00:01 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID| XYZ                  |  1002 |   166K|    40   (3)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | XYZ_CANCEL_STATE_IND |       |       |     8   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("D"."XYZ_BLOCKED" IS NULL)
       2 - access("D"."CANCEL_STATE"='N')
    SQL> select * from sb11.dnr d
      2  where d.dnr_blocked IS NULL and d.cancel_state = 'N'
      3* and d.payed = 'N'
    SQL> /
    Execution Plan
    Plan hash value: 1292668880
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                      |  1001 |   166K|    89   (3)| 00:00:01 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID| XYZ                  |  1001 |   166K|    89   (3)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | XYZ_CANCEL_STATE_IND |       |       |    15   (0)| 00:00:01 |

  • Selecting values for query where clause

    hi guys, this is possibly a silly question but not sure if i am approaching the solution in the correct mannor.
    At the top of my form i have text box which the user fills in various values. These values are then used to refine the query results in the block below. I know i can go into the datablock being queried and set the where clause to equal the value of the text boxes above but i dont feel this is the right place to do it.
    If i do it that way when the text box above is blank it returns no reults when infact i want to query everything if the values are left blank. So should i put it in pre query? if so what way should it be done?
    Any help would be greatly appreciated.
    Thanks.

    Hello,
    If i do it that way when the text box above is blank it returns no reults when infact i want to query everything if the values are left blank. So should i put it in pre query? if so what way should it be done?Not really if you use like below in block's where clause...
    db_field_name1=NVL(:form_field_name1,db_field_name1) AND
    db_field_name2=NVL(:form_field_name2,db_field_name2)-Ammad

  • Dynamic Query Where Clause

    Hi,
    I have the following query in a SQL Query (Pl/Sql Function Body Returning Sql Query) report:
    DECLARE
    q VARCHAR2(32767); -- query
    w VARCHAR2(4000) ; -- where clause
    we VARCHAR2(1) := 'N'; -- identifies if where clause exists
    BEGIN
    q:= 'SELECT "OSP_ID",' ||
    ' "OSP_NUMBER",'||
    ' "PROPOSAL_TITLE",'||
    ' "PROPOSAL_TYPE",'||
    ' "AGENCY_TYPE_CODE",'||
    ' "AGENCY_TYPE",'||
    ' "AGENCY_CODE",'||
    ' "AGENCY_NAME",'||
    ' "AGENCY_ABBREVIATION",'||
    ' "SPONSOR_CODE",'||
    ' "SPONSOR_NAME",'||
    ' "PI_NAME",'||
    ' "PI_EMP_NUMBER",'||
    ' "PI_PERS_ID" '||
    ' FROM "PROPOSAL_V" ';
    IF :P25_OSP_NUMBER != '-All-'
    THEN
    w := ' OSP_NUMBER = :P25_OSP_NUMBER ';
    we := 'Y';
    END IF;
    IF :P25_PROPOSAL_TYPE != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    ELSE
    w := ' PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    we := 'Y';
    END IF;
    END IF;
    IF we = 'Y'
    THEN q := q || ' WHERE '|| w;
    END IF;
    RETURN q;
    END;
    What I need is to change the ' OSP_NUMBER = :P25_OSP_NUMBER ';
    to ' OSP_NUMBER LIKE '%'||:P25_OSP_NUMBER'%'|| ';
    But I'm getting errors when I do like above.
    Can somebody please help...
    Thanks in advance
    - Pradeep

    First of all, get rid of that silly "where exists" variable, just add a where clause like where 1=1 to the query and keep adding dynamic clauses with AND clause as needed.
    Try
    q := q||'and OSP_NUMBER LIKE ''%'''||:P25_OSP_NUMBER||'''%''';

  • Dimension Mapping in 11g. Can Where clause be used to filter source table?

    Hi,
    Is it possible to use a where clause filter when mapping a dimension to source table in AWM 11g
    My understanding of the user guide is that filters can only be used in cube mapping?
    I am using AWM 11.2.0.1.0A on db 11g R2.
    I presume I could use a database view on the source table to filter down to the records for the dimension, however, I understand this would then prevent me refreshing any cube using this dimension using materialized view refresh?
    Thanks

    Yes, you can apply a where clause on a dimension map, but it is not exposed through AWM. You would need to add an attribute to the XML of the form
    WhereClause='<source table condition>'For example, you could add this to a HierarchyLevelMap.
    <HierarchyLevelMap
      WhereClause="CUSTOMER_DIM.SHIP_TO_ID = 123"
      KeyExpression="CUSTOMER_DIM.SHIP_TO_ID"
      Query="CUSTOMER_DIM">
    </HierarchyLevelMap>Make sure you add it to all relevant levels in a hierarchy. E.g. all levels that share the same source table. This is compatible with MV refresh. You can also map it to a view containing the where clause, and that, too, should work with MV refresh.

  • Query SQL datastore with XML where clause source

    Hope I am in the right place.  New to Bus Obj Data Services Designer....I have cerated xml schemas, added it to the page as an xml source in.  Mapped a test xml file and all is well there.  I have added a query that grabs the xml.
    I need to then query the MS SQL datastore ans use  the data form the xml query as the where clause.  How is this done?  Or do I put a query on the datastore for all the data in a table then do anotehr query filtering one with the other?  seems like that would be rather heavy and low performance.  The results will then be sent back out as xml (schema and test file already set up as an xml out)
    Thanks!

    Thanks for the tips.
    I'm trying to implement this option, using your ViewDefHelper.
    I´m running into a problem though. After I create my dynamic View Object using a ViewDef, I need to create some view links.
    So I get the AttributeDefs of the columns (source, and destination) from the method findAttributeDef (which is the whole purpose of performance in my post). This method is returning the correct Attribute Def, but when I create the view Link with the method createViewLinkBetweenViewObjects(java.lang.String vlName,
    java.lang.String accessorName,
    ViewObject master,
    AttributeDef[] srcAttrs,
    ViewObject detail,
    AttributeDef[] destAttrs,
    java.lang.String assocClause)
    My destination query is generating the where clause as:
    null = ?
    Any Ideas what I'm doing wrong ?
    Thanks again.
    John.

  • Using Date in where clause

    Hello all,
    I am new to Oracle, currently using 10G + aspvbscript.
    I've been trying to query data using date in where clause but nothing seems to work.
    The column is in date format.
    It gets printed out like this: 5/1/2010 11:21:19 AM
    I tried using this query:
    SELECT * from table where TRUNC(user_date) > to_date('FEB-01-2010:00:00:00','mm-dd-yyyy:HH24:MI:SS') order by user_date asc.
    It does return an output but it returns everything in table and does not take WHERE clause into consideration however, it does sort the date in ascending order.
    I've tried getting rid of TRUNC tried to format date in a different way but no such luck.
    Please point me to the right direction.
    Thanks.

    Welcome to the forums!
    In cases like this it is helpful if you can provide the following information:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    I'll try and take a stab at your request based on the data given. What your query says is that it will return all rows that have a date greater then 2/1/2010 (MM/DD/YYYY). If your query is returning all rows then maybe the possibility exists that all the dates in the table are greater then 2/1/2010. Have you checked all dates to see if this is the case?
    Also, one note about your TO_DATE() function.to_date('FEB-01-2010:00:00:00','mm-dd-yyyy:HH24:MI:SS')The date format does not match the string you are using with respect to month. Your string has 'FEB' but the format is 'MM' which is the numeric representation of the month. Although Oracle was able to convert it to the proper date on my system you should try and maintain consistency between the string and the date format used.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • How to change the semantic color of entire rows in a table.

    Hi, in the past I already managed to change the semantic color of a cell by a condition (for example all the cells with negative number -> I set negative semantic color) My question is how can I change the semantic color of the entire row where this

  • Insert Record in Master-Detail block

    I am using JDev 10.1.2, Struts, ADF and JSP I have a Master-Detail relationship. As the master table(Course) is browsed , the details(Students) record keep changing. Now I want to insert records to the detail (Students) block alone. I am generating t

  • Old Photoshop version download (Photoshop CS, Photoshop 8.0)

    Hello to everyone, i work for a small editorial company, i found out that we have some old Photoshop CS (Photoshop 8.0) licences and i want to use one of them, but the installation cds are missing. Is there a place where i can download the installati

  • Script to edit 'isCriticalSystemObject' attribute

    Is it possible to write a script to set an OU that contains security groups' attribute 'isCriticalSystemObject' to true? Sean

  • Formating in Jabber (Background Colour)

    Hello, I noticed recently that iChat sends with the XHTML-IM stanza always the background and font colour settings. Which look like this: <body xmlns="http://www.w3.org/1999/xhtml" style="background-color:#C0E668;color:#000000" > Which annoys some pe