Dbms_advanced_rewrite predicates

Is it possible to specify a predicate (aside from a join condition) in source/target sql in dbms_advanced_rewrite? None of the examples to be found appear to demonstrate this capability. I would have expected to be able to represent some sort of bind variable in the query, but this doesn't seem to be permitted. If I'm not missing something; this makes what was an exciting prospect rather useless.
SQL> BEGIN
2 SYS.DBMS_ADVANCED_REWRITE.DECLARE_REWRITE_EQUIVALENCE
3 ('AT_TEST',
4 'SELECT FULL_NAME FROM TMP_NASDAQTRADER_MPID',
5 'SELECT FULL_NAME FROM TMP_NASDAQTRADER_MPID WHERE MPID = :BND',
6 FALSE);
7 END;
8 /
PL/SQL procedure successfully completed.
SQL> ALTER SESSION SET query_rewrite_enabled = TRUE;
Session altered.
SQL> ALTER SESSION SET query_rewrite_integrity = trusted;
Session altered.
SQL> SELECT /*+REWRITE_OR_ERROR*/ FULL_NAME FROM TMP_NASDAQTRADER_MPID WHERE MPID = 'SUFI'; 
SELECT /*+REWRITE_OR_ERROR*/ FULL_NAME FROM TMP_NASDAQTRADER_MPID WHERE MPID = 'SUFI'
ERROR at line 1:
ORA-30393: a query block in the statement did not rewrite
SQL>

SQL> SELECT COUNT(*) FROM SATYA_1;
COUNT(*)
29
SQL> SELECT COUNT(*) FROM SATYA_2;
COUNT(*)
1
EXEC SYS.DBMS_ADVANCED_REWRITE.DECLARE_REWRITE_EQUIVALENCE ('TEST_QRW','SELECT COUNT(*) FROM SATYA_1','SELECT COUNT(*) FROM SATYA_2',FALSE,'text_match');
PL/SQL procedure successfully completed.
SQL> SELECT COUNT(*) FROM SATYA_1;
COUNT(*)
29
Result should : 1

Similar Messages

  • Quesion about dbms_advanced_rewrite ???

    SCOTT@oracle10g>alter session set nls_language=american;
    Session altered.
    SCOTT@oracle10g>create table tt1 as select * from user_objects;
    Table created.
    SCOTT@oracle10g>create table tt2 as select * from dba_objects where owner='SYSTEM';
    Table created.
    SCOTT@oracle10g>exec dbms_stats.gather_table_stats(user,'TT1');
    PL/SQL procedure successfully completed.
    SCOTT@oracle10g>exec dbms_stats.gather_table_stats(user,'TT2');
    PL/SQL procedure successfully completed.
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2);
    Execution Plan
    Plan hash value: 720405399
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |    20 |  1600 |    45   (0)| 00:00:01 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TT1  |    21 |  1680 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |     1 |     5 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TT2" "TT2" WHERE
                  LNNVL("OBJECT_ID"<>:B1)))
       3 - filter(LNNVL("OBJECT_ID"<>:B1))
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2
      2  where object_id is not null) and object_id is not null;
    Execution Plan
    Plan hash value: 2268948225
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     2 |   170 |     8  (13)| 00:00:01 |
    |*  1 |  HASH JOIN ANTI    |      |     2 |   170 |     8  (13)| 00:00:01 |
    |*  2 |   TABLE ACCESS FULL| TT1  |    21 |  1680 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |   469 |  2345 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("OBJECT_ID"="OBJECT_ID")
       2 - filter("OBJECT_ID" IS NOT NULL)
       3 - filter("OBJECT_ID" IS NOT NULL)
    SCOTT@oracle10g>begin
      2    sys.dbms_advanced_rewrite.DECLARE_REWRITE_EQUIVALENCE('TEST','select * from tt1 where object_
    id not in (select object_id from tt2)','select * from tt1 where object_id not in (select object_id f
    rom tt2 where object_id is not null) and object_id is not null',false,'text_match');
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SCOTT@oracle10g>alter session set query_rewrite_integrity=trusted;
    Session altered.
    SCOTT@oracle10g>set autot trace exp
    SCOTT@oracle10g>alter session set sql_trace=true;
    Session altered.
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2);
    Execution Plan
    Plan hash value: 2268948225
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     2 |   170 |     8  (13)| 00:00:01 |
    |*  1 |  HASH JOIN ANTI    |      |     2 |   170 |     8  (13)| 00:00:01 |
    |*  2 |   TABLE ACCESS FULL| TT1  |    21 |  1680 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |   469 |  2345 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("OBJECT_ID"="OBJECT_ID")
       2 - filter("OBJECT_ID" IS NOT NULL)
       3 - filter("OBJECT_ID" IS NOT NULL)
    SCOTT@oracle10g>insert into tt1(object_id) select object_id from tt2;
    469 rows created.
    SCOTT@oracle10g>exec dbms_stats.gather_table_stats(user,'TT1');
    PL/SQL procedure successfully completed.
    SCOTT@oracle10g>set autot trace exp
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2);
    Execution Plan
    Plan hash value: 720405399
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |   489 |  7824 |   991   (1)| 00:00:12 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TT1  |   490 |  7840 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |     1 |     5 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TT2" "TT2" WHERE
                  LNNVL("OBJECT_ID"<>:B1)))
       3 - filter(LNNVL("OBJECT_ID"<>:B1))
    SCOTT@oracle10g>set autot off
    SCOTT@oracle10g>select sql_id,child_number from v$sql where sql_text='select * from tt1 where object
    _id not in (select object_id from tt2)';
    SQL_ID        CHILD_NUMBER
    dwag5726g0j91            1
    SCOTT@oracle10g>select * from table(dbms_xplan.display_cursor('dwag5726g0j91',1));
    PLAN_TABLE_OUTPUT
    SQL_ID  dwag5726g0j91, child number 1
    select * from tt1 where object_id not in (select object_id from tt2)
    Plan hash value: 720405399
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |       |       |   991 (100)|          |
    |*  1 |  FILTER            |      |       |       |            |          |
    PLAN_TABLE_OUTPUT
    |   2 |   TABLE ACCESS FULL| TT1  |   490 |  7840 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |     1 |     5 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( IS NULL)
       3 - filter(LNNVL("OBJECT_ID"<>:B1))
    21 rows selected.
    SCOTT@oracle10g>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Productionwhen I modify tt1,query rewrite don't take effect ??

    hi sir,
    it take effects,but there are some problems.
    SCOTT@oracle10g>insert into tt1(object_id) select object_id from tt2;
    469 rows created.
    Execution Plan
    Plan hash value: 1248358058
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT  |      |   469 |  2345 |     4   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| TT2  |   469 |  2345 |     4   (0)| 00:00:01 |
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2); 
    Execution Plan
    Plan hash value: 720405399
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |   506 |  9614 |  1026   (1)| 00:00:13 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| TT1  |   507 |  9633 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| TT2  |     1 |     5 |     4   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TT2" "TT2" WHERE
                  LNNVL("OBJECT_ID"<>:B1)))
       3 - filter(LNNVL("OBJECT_ID"<>:B1))
    SCOTT@oracle10g>commit;
    Commit complete.
    SCOTT@oracle10g>select * from tt1 where object_id not in (select object_id from tt2);
    Execution Plan
    Plan hash value: 2314021845
    | Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |      |    38 |   912 |     8  (13)| 00:00:01 |
    |*  1 |  HASH JOIN RIGHT ANTI|      |    38 |   912 |     8  (13)| 00:00:01 |
    |*  2 |   TABLE ACCESS FULL  | TT2  |   469 |  2345 |     4   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL  | TT1  |   507 |  9633 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("OBJECT_ID"="OBJECT_ID")
       2 - filter("OBJECT_ID" IS NOT NULL)
       3 - filter("OBJECT_ID" IS NOT NULL)
       when I declare a new rewrite,enq: RW - MV metadata contention happens,and the blocking_session and blocked session are same session .
    SYS@oracle10g>col event for a50
    SYS@oracle10g>set linesize 300
    SYS@oracle10g>select sid,serial#,event,blocking_session from v$session where username='SCOTT';
           SID    SERIAL# EVENT                                              BLOCKING_SESSION
           157          7 enq: RW - MV metadata contention                                157

  • Index usage for retrieving data  without filter predicate

    Hi,
    does someone have a explanation for the following scenario:
    I have a table T1 with an index OID_IX on column ( object_id ) - The table is a CTAS from dba_objects just to populate it with data.
    There are no other Indexes present. The table and the index are analyzed !
    When I run the following query the table is accessed FULL ( not using the index )
    SELECT OBJECT_ID FROM T1;
    SQL> select object_id from t1;
    485984 rows selected.
    Elapsed: 00:00:01.76
    Execution Plan
    Plan hash value: 3617692013
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 485K| 2372K| 1528 (1)| 00:00:19 |
    | 1 | TABLE ACCESS FULL| T1 | 485K| 2372K| 1528 (1)| 00:00:19 |
    Statistics
    1 recursive calls
    0 db block gets
    7396 consistent gets
    0 physical reads
    0 redo size
    2887158 bytes sent via SQL*Net to client
    5684 bytes received via SQL*Net from client
    487 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    485984 rows processed
    But if I add a predicate ( even though it is useless in this case ) the index is taken and the query runs faster:
    JDBC@toekb> select object_id from t1 where object_id != -999;
    485960 rows selected.
    Elapsed: 00:00:01.40
    Execution Plan
    Plan hash value: 3555700789
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 485K| 2372K| 242 (3)| 00:00:03 |
    |* 1 | INDEX FAST FULL SCAN| OID_IX | 485K| 2372K| 242 (3)| 00:00:03 |
    Predicate Information (identified by operation id):
    1 - filter("OBJECT_ID"<>(-999))
    Statistics
    1 recursive calls
    0 db block gets
    1571 consistent gets
    0 physical reads
    0 redo size
    2766124 bytes sent via SQL*Net to client
    5684 bytes received via SQL*Net from client
    487 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    485960 rows processed
    here my setup:
    sqlsql--
    drop table t1 purge ;
    create table t1 tablespace users as select * from dba_objects;
    insert into t1 ( select * from t1);
    commit;
    insert into t1 ( select * from t1);
    commit;
    insert into t1 ( select * from t1);
    commit;
    create index oid_ix on t1 (object_id) tablespace users ;
    exec dbms_stats.gather_table_stats(null,'t1',cascade=>true, estimate_percent=>100);
    sqlsql--
    In my case the Table and Index looks this way:
    JDBC@toekb> select table_name, NUM_ROWS,BLOCKS,AVG_SPACE from user_tables;
    TABLE_NAME NUM_ROWS BLOCKS AVG_SPACE
    =======================================
    T1 485984 6944 0
    Elapsed: 00:00:00.11
    JDBC@toekb> select INDEX_NAME,BLEVEL,LEAF_BLOCKS,DISTINCT_KEYS,NUM_ROWS from user_indexes;
    INDEX_NAME BLEVEL LEAF_BLOCKS DISTINCT_KEYS NUM_ROWS
    ===================================================
    OID_IX 2 1074 60745 485960
    Elapsed: 00:00:00.07
    The table holds 7 times more blocks than the index !
    any reply welcome
    best regards
    Edited by: guenterp on Aug 12, 2010 2:44 PM

    guenterp wrote:
    Hi,
    does someone have a explanation for the following scenario:
    I have a table T1 with an index OID_IX on column ( object_id ) - The table is a CTAS from dba_objects just to populate it with data.
    There are no other Indexes present. The table and the index are analyzed !
    When I run the following query the table is accessed FULL ( not using the index )
    SELECT OBJECT_ID FROM T1;
    SQL> select object_id from t1;
    485984 rows selected.
    Elapsed: 00:00:01.76
    Execution Plan
    Plan hash value: 3617692013
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 485K| 2372K| 1528 (1)| 00:00:19 |
    | 1 | TABLE ACCESS FULL| T1 | 485K| 2372K| 1528 (1)| 00:00:19 |
    Statistics
    1 recursive calls
    0 db block gets
    7396 consistent gets
    0 physical reads
    0 redo size
    2887158 bytes sent via SQL*Net to client
    5684 bytes received via SQL*Net from client
    487 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    485984 rows processed
    But if I add a predicate ( even though it is useless in this case ) the index is taken and the query runs faster:
    JDBC@toekb> select object_id from t1 where object_id != -999;
    485960 rows selected.
    Elapsed: 00:00:01.40
    Execution Plan
    Plan hash value: 3555700789
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 485K| 2372K| 242 (3)| 00:00:03 |
    |* 1 | INDEX FAST FULL SCAN| OID_IX | 485K| 2372K| 242 (3)| 00:00:03 |
    Predicate Information (identified by operation id):
    1 - filter("OBJECT_ID"<>(-999))
    Statistics
    1 recursive calls
    0 db block gets
    1571 consistent gets
    0 physical reads
    0 redo size
    2766124 bytes sent via SQL*Net to client
    5684 bytes received via SQL*Net from client
    487 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    485960 rows processed
    here my setup:
    sqlsql--
    drop table t1 purge ;
    create table t1 tablespace users as select * from dba_objects;
    insert into t1 ( select * from t1);
    commit;
    insert into t1 ( select * from t1);
    commit;
    insert into t1 ( select * from t1);
    commit;
    create index oid_ix on t1 (object_id) tablespace users ;
    exec dbms_stats.gather_table_stats(null,'t1',cascade=>true, estimate_percent=>100);
    sqlsql--
    In my case the Table and Index looks this way:
    JDBC@toekb> select table_name, NUM_ROWS,BLOCKS,AVG_SPACE from user_tables;
    TABLE_NAME NUM_ROWS BLOCKS AVG_SPACE
    =======================================
    T1 485984 6944 0
    Elapsed: 00:00:00.11
    JDBC@toekb> select INDEX_NAME,BLEVEL,LEAF_BLOCKS,DISTINCT_KEYS,NUM_ROWS from user_indexes;
    INDEX_NAME BLEVEL LEAF_BLOCKS DISTINCT_KEYS NUM_ROWS
    ===================================================
    OID_IX 2 1074 60745 485960
    Elapsed: 00:00:00.07
    The table holds 7 times more blocks than the index !
    any reply welcome
    best regards
    Edited by: guenterp on Aug 12, 2010 2:44 PMSorry, but I am in doubt with your statists:
    Statistics
    1 recursive calls
    0 db block gets
    7396 consistent gets
    0 physical reads ---->>>>>>>>>>>> Why it is 0 in any case(bnoth full scan and index FFS)
    0 redo size
    2887158 bytes sent via SQL*Net to client
    5684 bytes received via SQL*Net from client
    487 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    485984 rows processedCould you pls retry below operation before execuion of each sql:
    alter system flush buffer_cache;In my case with 10.2.0.4 on HPUX:
    SQL> exec dbms_stats.gather_table_stats(null,'t1',cascade=>true, estimate_percent=>100);
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.61
    SQL> alter system flush buffer_cache;
    System altered.
    Elapsed: 00:00:14.00
    SQL> select * from t1;
    82016 rows selected.
    Elapsed: 00:00:06.48
    Execution Plan
    Plan hash value: 838529891
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      | 82016 |  6888K|   394   (1)| 00:00:05 |
    |   1 |  TABLE ACCESS FULL| T1   | 82016 |  6888K|   394   (1)| 00:00:05 |
    Statistics
              0  recursive calls
              0  db block gets
           6455  consistent gets
           1039  physical reads
              0  redo size
        3480570  bytes sent via SQL*Net to client
          38508  bytes received via SQL*Net from client
           5469  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          82016  rows processed
    SQL> alter system flush buffer_cache;
    System altered.
    Elapsed: 00:00:18.26
    SQL> select * from t1 where object_id !=999;
    81976 rows selected.
    Elapsed: 00:00:07.09
    Execution Plan
    Plan hash value: 838529891
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      | 81976 |  6884K|   394   (1)| 00:00:05 |
    |*  1 |  TABLE ACCESS FULL| T1   | 81976 |  6884K|   394   (1)| 00:00:05 |
    Predicate Information (identified by operation id):
       1 - filter("OBJECT_ID"<>999)
    Statistics
              0  recursive calls
              0  db block gets
           6443  consistent gets
           1039  physical reads
              0  redo size
        3478961  bytes sent via SQL*Net to client
          38494  bytes received via SQL*Net from client
           5467  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          81976  rows processed
    SQL>

  • How can we specify the order of the predicates execution?

    I am going to write the following query
    select answer, answer_id from surveys s join answers a on s.survey_id = a.survey_seq_id
    where question_uid = 206400374 and insertdate = to_date('31/12/2012') and answer > 0;However, when I look at the execution plan, I see that the last predicate (to_number(answer) > 0) has been executed the first. Henceforth, it checks many rows first. Normally, 75 rows belong to 31/12/2012 as you see from the following. Can I specify the execution order?
    select count(*) from surveys s join answers a on s.survey_id = a.survey_seq_id
    where question_uid = 206400374 and insertdate = to_date('31/12/2012');
    COUNT(*)
    75If so, how? Because, the type of answer is varchar2 and some of answers contain text characters such as 'Yes' or 'No'. Therefore, before 31/12/2012 some answers contain 'Yes' or 'No'. However in 31/12/2012 all answers are numeric.
    Plan hash value: 3217836037
    | Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |         |     2 |    68 |  9401   (1)| 00:01:53 |
    |*  1 |  HASH JOIN         |         |     2 |    68 |  9401   (1)| 00:01:53 |
    |*  2 |   TABLE ACCESS FULL| SURVEYS |     2 |    26 |   239   (1)| 00:00:03 |
    |*  3 |   TABLE ACCESS FULL| ANSWERS |   337 |  7077 |  9162   (1)| 00:01:50 |
    Predicate Information (identified by operation id):
       1 - access("S"."SURVEY_ID"="A"."SURVEY_SEQ_ID")
       2 - filter("S"."INSERTDATE"=TO_DATE(' 2012-12-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss'))
       3 - filter("A"."QUESTION_UID"=206400374 AND
                  TO_NUMBER("A"."ANSWER")>0)
    select distinct answer from surveys s join answers a on s.survey_id = a.survey_seq_id
    where question_uid = 206400374 and insertdate = to_date('31/12/2012');
    ANSWER
    1
    3
    0
    2And, also I can execute the following query without any error
    select to_number(answer) from surveys s join answers a on s.survey_id = a.survey_seq_id
    where question_uid = 206400374 and insertdate = to_date('31/12/2012');

    In answer to your original question:
    970992 wrote:
    However, when I look at the execution plan, I see that the last predicate (to_number(answer) > 0) has been executed the first. Henceforth, it checks many rows first. Normally, 75 rows belong to 31/12/2012 as you see from the following. Can I specify the execution order?According to the execution plan, it will do a full scan of surveys using the predicate on insertdate to build the (presumably in-memory) hash table (hash based on survey_id) to do the joins (Step 2). Then, it does a full scan of the answers table using the question_uid and answer predicates (Step 3). For each row it finds that matches those predicate, it will prpobe the hash table created in step 2 using the hashed value of survey_seq_id. So, it is doing the insertdate predicate first.
    In answer to your last post
    970992 wrote:
    >
    First of all i would get rid of the implizit type conversion:
    TO_NUMBER("A"."ANSWER")>0)it is not implicit conversion, I reckon it is explicit type conversion, isnt it?
    No, it is an implicit type conversion. Your code says answer > 0, since the answer column is a varchar2 column, Oracle implicitly converts the answer column to a number to compare against the number on the right side of the comparison. Note that if something like 'A' ever becomes a valid answer, then this query will fail with ORA-01722: invalid number.
    >
    >
    Obviously "A"."ANSWER" is not a number colmun, problably varchar, so use something like
    A.ANSWER != "0"
    or
    A.ANSWER > "0"Yes answer column is varchar2 but can you type A.ANSWER > "0" as a predicate? I mean, you can not varchar > varchar, can you?
    Of course you can use inequality predicates on a varcahr column. Is the string A greater than the string B?
    Based on the explain plan, your statistics might be a little off, not hugely so. The esitmates are at least in the right order of magnitude based on what you have posted so far.
    What indexes, if any, are available on the two tables?
    John

  • 11g-[nQSError: 42029] Subquery contains too many values for the IN predicat

    Hi,
    I am having 2 reports one is for subquery which returns inputs to Main report. Actually the report was working fine in 10g. But in 11g we are gettting following error:
    View Display Error
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 42029] Subquery contains too many values for the IN predicate.Please have your System Administrator look at the log for more details on this error. (HY000)
    Please have your System Administrator look at the log for more details on this error.
    Getting same error after modofying the parameter value MAX_EXPANDED_SUBQUERY_PREDICATES to 12000
    Please suggest what could be the other reason it may fail or any other settings we need to check.
    Regards,
    ckeng

    ckeng,
    Normally the IN clause has restriction of 10000 values in general sql/plsql we will go with inline queries i think model your rpd to generate inner queries
    select * from emp where dept_id in (Select distinct dept_id from dept);
    or have a condition/filter on sub report and make one more inner report with sub-filter but definitely it will cause performance issues.
    thanks,
    Saichand.v

  • Error while Using Predicate to search by modify date

    I am using ipredicate java api class to search on the basis of modify date
    I am getting the following exception
    Caused by: java.lang.RuntimeException: PCE Exception caught in BPEL Server: Predicate value type is invalid.
    Predicate value type is not same as column data type used to create the predicate
    I am setting Calendar as Value in predicate to search
    Please help

    Hi Sharad,
    Put ('') in your command,
    wls:/offline> execfile('c:/create_server.py')
    Regards
    Edited by: scapy on Oct 6, 2011 4:15 PM

  • SQL select query having more than 1000 values in 'IN' clause of predicate.

    Hi,
    We are executing a select query from a table and showing it through a front end screen. When the count of values given in the 'IN' clause of predicate are exceeding 1000 , it is throwing error.
    eg. select * from Employees where emp.Id. in('111',123','121','3232',........1001 Ids)
    We are using Oracle version 10.2.0.
    Please suggest how to tackle such issue.
    Regards,
    Naveen Kumar.C.
    Edited by: Naveen Kumar C on Aug 30, 2008 10:01 PM

    Use a nested table:
    create or replace type numbertype
    as object
    (nr number(20,10) )
    create or replace type number_table
    as table of numbertype
    create or replace procedure tableselect
    ( p_numbers in number_table
    , p_ref_result out sys_refcursor)
    is
    begin
    open p_ref_result for
         select *
    {noformat}     from   employees
         ,        (select /*+ cardinality(tab 10) */ tab.nr
                   from   table(p_numbers) tab) tbnrs
         where id = tbnrs.nr;
    end;
    /{noformat}
    Using nested tables will reduce the amount of parsing because the sql statement uses binded variables! The cardinality hint causes Oracle to use the index on employees.id.

  • Using Predicate filters in a Custom component

    Hello,
    I have a cusom datagrid component, which gets it's data from a XMLListCollection object. The xmlList is a simple <employess><employe1><fname/><lname/></emloye1></employees>
    I have a text input as a part of this custom component. I am creating a change event on the control to trigger a filter function filterGrid(). I want the frid to dynamically change data as the user types the characters. Currently i have hardcoded my predicate filter to filter the grid whenever the first char matches J. How can i change this to read the chars from the text input.
                private function filterGrid(event:Event):void {
                    if(text1.text!="") {
                        myXMLCollection.filterFunction = filterEmp;
                    }else {
                        myXMLCollection.filterFunction = null;
                    myXMLCollection.refresh();
                private function filterEmp(item:XML):Boolean {
                    var searchResult:XMLList;
                    searchResult = item.(/^J/.test( fname ) );//Help need here
                    trace(searchResult);
                    if(searchResult.length()>0) {
                        return true;
                    return false;
    Thanks,

    I got this to work
    var pattern2:RegExp = new RegExp(text1.text, "i");\
    searchResult = item.(pattern2.test( fname ) || pattern2.test(lname) );
    But have another problem, the regex matches any charater and not the first chars as i type them for example
    IF i have
    John Macey
    Tracy Jordon
    and if i type 'c' in the textnpt i get both John Macey and Tracy Jordon.
    Will dig further,

  • Predicate push down in 10.2.0.3 but not in 11.1.0.7

    In the SQL and PL/SQL forum, there was an interesting question on why a predicate isn't pushed down in an 11.1.0.7 database while 10.2.0.3 did push the predicate, here: Same query works OK on 10.2.0.3 and not OK on 11.1.0.7-please help
    The last post contains 10053 trace output. Maybe any of the performance experts in this forum has an explanation?
    Regards,
    Rob.

    SQL> ALTER TABLE LOGIN ADD (
      2  CONSTRAINT FK_LOGIN_MPI
      3  FOREIGN KEY (MPID)
      4  REFERENCES PERSON_ID (MPID));
    REFERENCES PERSON_ID (MPID))
    ERROR at line 4:
    ORA-02270: no matching unique or primary key for this column-list
    SQL> Select
      2  rn,
      3  mpid,
      4  first,
      5  middle,
      6  last,
      7  account_status,
      8  username,
      9  last_login,
    10  date_added,
    11  degree,
    12  ssn
    13  from
    14  (
    15  Select
    16  rownum as rn,
    17  mpid,
    18  first,
    19  middle,
    20  last,
    21  account_status,
    22  username,
    23  last_login,
    24  date_added,
    25  degree,
    26  ssn
    27  from
    28  (
    29  SELECT distinct
    30  p.mpid as mpid,
    31  UPPER(name_first) as first,
    32  UPPER(name_middle_initial) as middle,
    33  UPPER(name_last) as last,
    34  l.account_status,
    35  username,
    36  TO_CHAR(last_login, 'DD-Mon-YYYY') as last_login,
    37  TO_CHAR(date_added, 'DD-Mon-YYYY') as date_Added,
    38  degree,
    39  ssn
    40  FROM
    41  PERSON_ID p,
    42  login l
    43  WHERE
    44  p.mpid=l.mpid AND UPPER(p.name_last) LIKE '%SMITH%'
    45  ORDER BY
    46  name_last ASC
    47  )
    48  )
    49  where
    50  rn >= 1 and rn <= 20;
    name_last ASC
    ERROR at line 46:
    ORA-01791: not a SELECTed expression
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bi
    PL/SQL Release 10.1.0.5.0 - Production
    CORE    10.1.0.5.0      Production
    TNS for Solaris: Version 10.1.0.5.0 - Production
    NLSRTL Version 10.1.0.5.0 - Productionbon, je n'ai pas de 10.1.0.4 windows, mais je doute que ça fasse vraiment la différence
    donne moi l'output dans sqlplus

  • Problem with complex predicates

    Hi,
    i'm trying to create a complex predicate to query for some tasks.
    I have 2 predicates, and i'm trying to create a complex one with the following code:
    complexPred = new Predicate(pred1, Predicate.AND, pred2);
    I have no problems when querying for tasks with either pred1 or pred2, but when executing the query with complexPred, i get a null pointer exception.
    I realised that complexPred has an empty clause list. Am I missing something when creating the complex predicate?
    Thanks in advanced

    Thanks for the example, but i have the same problem running it as I exposed in my previous post.
    When I reach this point in the code...
    Predicate predicate = null;
    if ( predicateSearch == null ) {         
    predicate = predicateBasic;
    } else {         
    predicate = new Predicate (predicateBasic,Predicate.AND,predicateSearch);
    ...both predicateSearch and predicateBasic have content, and when they are combined into predicate, this new variable predicate has an empty clause list (predicate.getPredicateClauseList() is an empty ArrayList, while predicateSearch.getPredicateClauseList() and predicateBasic.getPredicateClauseList() have both content)
    The rest of the components of the variable predicate (tables, values...) seems to be ok and a result of the combination of predicateBasic and predicateSearch
    This is part of the log I get:
    <*::*> <displayColumn xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">urlAttribute1</displayColumn>
    <*::*> <displayColumn xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">urlAttribute2</displayColumn>
    <*::*> </displayColumnList>
    <*::*> <optionalInfoList xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">
    <*::*> <taskOptionalInfo xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">Actions</taskOptionalInfo>
    <*::*> </optionalInfoList>
    <*::*> <predicate xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">
    <*::*> <assignmentFilter xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">My+Group</assignmentFilter>
    <*::*> </predicate>
    <*::*> <ordering xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">
    <*::*> <clause xmlns="http://xmlns.oracle.com/bpel/workflow/taskQuery">
    <*::*> <col
    As you can see after assigmentFilter, the label predicate is closed, and is missing a label clause with all the clauseList information
    Thanks in advanced,
    Cris
    Edited by: user7352348 on 07-nov-2011 23:47

  • Last Fetched Predicate statement in active sync process

    Can anybody tell me what should be the Last Fetched Predicate and Static Search Predicate for a changelog table with seqno column for polling to a sql database.
    From this post, http://forum.java.sun.com/thread.jspa?forumID=764&threadID=5104031
    let say I have a polling to a changelog db table with a seq number and it will have to read from this table. But, in my case, I just need to look for a code in the table to fire a workflow.What would be the good approach to achieve this requirement?

    Hi,
    If lastmod is a varchar2 in the database,
    then you need to say:
    lastmod > '$(var)'
    where var is the identity manager variable
    that lastmod is mapped to in the resource schema.
    Basically, if you say:
    x > '$(y)'
    x must be a field name in the database
    y must be the identity manger variable it
    maps to in the schema in the
    resource adapter configuration.
    If you edit the resource schema from the
    identity manager web interface, you should
    be able to see the mapping.
    Hope this helps,
    John I

  • Predicates for XPath in Condition Editor of NWDS for PI AEX 7.4 (SP 7)

    Dear all,
    we are in the middle of migrating from our old Dual Stack PI 7.0 to our new PI 7.4 AEX.
    We have a fairly largen receiver determination on the old system that makes heavy use of predictes. One expression for example looks like this
    (SHPMNT05/IDOC/E1EDT20/E1EDL20/E1EDL37/E1EDL49/E1EDL50[XSIQUALF='EEIVERF']/VLABDATA = 01)
    However, when I'm trying to insert this in NWDS' condition editor there's an error stating "Predicates are only allowed with EXISTS operator"
    1. Is this a limitation of the condition editor in NWDS?
    2. Is there a way to configure the above XPath so it is working in NWDS?
    3. Would it be safe / wise to configure the mappig in ICO in Swing Tool or would this be overwritten by NWDS configuraiton?
    Many thanks
    Jens

    Hi Jens
    From SAP library, the example shows that the usage of predicate is with the EX operator, so maybe it is a limitation.
    Integration Directory - SAP Library
    Maybe you can try to combine your two conditions in the predicate and use it with the EX operator
    (SHPMNT05/IDOC/E1EDT20/E1EDL20/E1EDL37/E1EDL49/E1EDL50[XSIQUALF='EEIVERF' and VLABDATA = '01'] EX)
    Rgds
    Eng Swee

  • Using an IN predicate in a PreparedStatement

    Is there a clean way to handle the IN predicate in Oracle's PreparedStatement. I guess the obvious way to do it would be thus:
    ps = SELECT * FROM someTable WHERE id IN (?, ?, ?)
    But this means that every time you use a different number of IDs, you would create a new PreparedStatement. If the number of IDs is highly variable, you would end up polluting you statement cache with seldom-used PrepareStatements.
    Is there a easier way to send in a list of values for the IN predicate?

    Fred,
    You can try using an Oracle collection type, like VARRAY that maps to "java.sql.Array" and the TABLE [SQL] operator, but I don't know if this will perform better than a simple "IN" list.
    I think if you search the forum archives for ARRAY, you should find something relevant.
    Good Luck,
    Avi.

  • Using CASE in a SQL predicate to return variable IN values ...

    Environment:
    Oracle EE 10.2.0.2 on AIX 5.3
    I am trying to use a CASE statement in a SQL predicate to fill in the values needed in an 'IN' clause.
    Here is my test case:
    create table tt (model varchar2(10), brand varchar2(10));
    insert into tt (model, brand) values ('modela','ajax');
    insert into tt (model, brand) values ('modelb','ajax');
    insert into tt (model, brand) values ('modelc','acme');
    insert into tt (model, brand) values ('modeld','acme');
    insert into tt (model, brand) values ('modele','acme');
    insert into tt (model, brand) values ('modelf','zeus');
    insert into tt (model, brand) values ('modelg','zeus');
    insert into tt (model, brand) values ('modelh','mojo');
    insert into tt (model, brand) values ('modeli','mojo');
    insert into tt (model, brand) values ('modelj','mama');
    Here is what I'm attempting to do. For a given starting letter for a brand I would like all the models printed out whose brand starts with the entered letter.
    Here is what I started with:
    select model, (case '&brandfirstletter'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end) pred
    from tt
    where brand in
    (case '&brandfirstletter'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end);
    When executed I get 'no rows selected'
    I wanted to print out the results of my CASE statement just to be sure it was doing what I thought I wanted.
    When I comment out the WHERE clause to see what the PRED values are I get:
    gww@dwt1> /
    Enter value for brandfirstletter: a
    old 1: select model, (case '&brandfirstletter'
    new 1: select model, (case 'a'
    Enter value for brandfirstletter: a
    old 8: -- (case '&brandfirstletter'
    new 8: -- (case 'a'
    MODEL PRED
    modela ('ajax','acme')
    modelb ('ajax','acme')
    modelc ('ajax','acme')
    modeld ('ajax','acme')
    modele ('ajax','acme')
    modelf ('ajax','acme')
    modelg ('ajax','acme')
    modelh ('ajax','acme')
    modeli ('ajax','acme')
    modelj ('ajax','acme')
    I believe this is what I want the results of the CASE statement to look like when I select 'a' for the substitute variable but I don't get the output I would like from the table.
    What am I missing?
    Thanks very much!!
    -gary

    gwicke wrote:
    select model, (case '&brandfirstletter'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end) pred
    from tt
    where brand in
    (case '&brandfirstletter'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end);You can't do this.
    ok, let's imagine you provide an 'a' as your substitution variable. What you get as a result is...
    select model, (case 'a'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end) pred
    from tt
    where brand in
    (case 'a'
    when 'a' then '(''ajax'',''acme'')'
    when 'z' then '(''zeus'')'
    when 'm' then '(''mojo'')'
    end);
    so if we logically remove the case statement as oracle would do when processing...
    select model, ('(''ajax'',''acme'')') pred
    from tt
    where brand in ('(''ajax'',''acme'')');
    Are you really going to have a brand that is stored as
    (''ajax'',''acme'')as a single value?
    You can't dynamically assign values to an IN list.

  • Predicate boolean method...calculating whether or not a year is a Leap year

    I'm trying to get pointed in the right direction for this program. I am attempting to write a program that calculates whether or not an inputted year by the user is a valid leap year or not, however I'm having problems figuring out the method for this calculation.
    A predicate method boolean seems to be the right way, but I can't figure out exactly how. Here's what I've brainstormed thus far:
    Leap Year Conditions:
    1. Is divisible by 4.
    2. Is NOT divisible by 100.
    3. Is divisible by 4.
    public class Year
              public boolean isLeapYear()
    }What confuses me is how to satisfy these conditions. Here is what I want to fill those '...' with. Excuse the tacky language coming up, but it's the only way I can express my thinking here:
    return ((inputted year) / 4) && (inputted year / 400) && !((inputted year) / 100)
    If the year is undivisible by any of these values then it could end up being a technical decimal (which means the inputtted year is not a leap year). But of course java would still calculate it anyway depending on how I defined the type.
    Should I try to implement a condition that if the variable returned by any of these calculations (except for 100) is a float point then the year is not a leap year? How would I do this?
    I'm really not sure where to go on this one. If anyone could point me in the right direction and give me a good start I would appreciate it. Thank you.
    Message was edited by:
    fairtex
    Message was edited by:
    fairtex

    http://en.wikipedia.org/wiki/Leap_year
    They have some leap year algorithms on there.

Maybe you are looking for

  • Does simple file and folder sharing on an iMac work with OSX Server?

    Hi There I wonder if I should install OSX Server on an iMac wher several users work on the same files and folders. My question - before I do something I might regret: Does simple file and folder sharing on an iMac within several users really work wit

  • How do I create a DVD with no menu ??

    Can I create a DVD that plays like a CD, using track numbers instead of a on-screen menu? I have several QT files, and I'd like to be able to jump between them using the buttons directly on the (commercial) DVD player... with no messing about in a DV

  • Ver.5.0.1.exe does not install even if all firefox prog. are closed

    on installation process, the install popbox says checking existing programs after which another popbox says close all firefox programs before installation.... I have closed all applications and programs prior to installation of the downloaded ver 5.0

  • Parameter in HTTP receiver adapter

    Hey My requirements are: I am sending an XML to an external system. Documentation says: "XML should be in a parameter in your request called 'xmlInput'". How do I actually put my XML in this parameter? Does this have anything to do with the URL Param

  • No entry in table T512W for key 40 9913

    Dear Guru When I am running simulation payroll run, system is throwing this error "No entry in table T512W for key 40 9913". 9913 is the wage type which is getting updated due to INCS rule. In the log, 9913 value is same as value of EDLI Contribution