invalid host / bind variable

Hello
I get the following problem when I am trying to pass a variable to link inside the IN clause of my SQL statement, which is also within a void query, although I don't think it will make a difference?
How can I change my SQL so that it will accept a bind variable?

EXAMPLE of the SQL problem:

SELECT manager_name
Managers
WHERE Group_id IN (SELECT Group_id
Groups
WHERE IN GroupName (: myBindVariable))
)



Thank you



Steve

You cannot use the lie for a value of list... You can use links for each individual value in such a list. But not for the entire list.

Maybe this helps:

http://asktom.Oracle.com/pls/asktom/f?p=100:11:1920953816309736:P11_QUESTION_ID:139812348065

Just to clarify more what I mean, here's an example of sqlplus with table DOUBLE:

15:46:35 SQL> variable b1 varchar2(40);
15:46:48 SQL> exec :b1 := 'X';

PL/SQL procedure successfully completed.

15:47:13 SQL> select *
15:47:15   2  from dual
15:47:17   3  where dummy in (:b1);
More...

D
-
X

1 row selected.

15:47:28 SQL> exec :b1 := '''X'',''Y'''

PL/SQL procedure successfully completed.

15:49:46 SQL> select *
15:49:50   2  from dual
15:49:55   3  where dummy in (:b1);

no rows selected

15:50:00 SQL> exec :b1 := 'X,Y';

PL/SQL procedure successfully completed.

15:50:15 SQL> select *
15:50:19   2  from dual
15:50:21   3  where dummy in (:b1);

no rows selected

15:50:26 SQL>

Published by: Toon Koppelaars on October 12, 2009 15:50

Tags: Database

Similar Questions

  • Immediate execution, to update and bind Variables

    I can't EXECUTE IMMEDIATE to work with an update statement when trying to link the name of the table. Consider the following example:
    create table gr_test(
      n Number);
      
    insert into gr_test (n) values(1);
    The anonymous block under works:
    declare
      update_statement Varchar2(2000);
    begin
      update_statement := '
      update gr_test
         set n = 2';
    
      execute immediate update_statement;
    end;
    but not
    declare
      update_statement Varchar2(2000);
    begin
      update_statement := '
      update :table_name
         set n = 2';
         
      execute immediate update_statement
        using 'gr_test';
    end;
    It gives ORA-00903 - invalid table name.

    You can not link the names of tables/columns using the clause Bind Variables (USING).

    You need to add to the dynamic SQL.

    Something this way:

     declare
       update_statement Varchar2(2000);
       v_table_name        varchar2(30);
     begin
       v_table_name = 'GR_TEST';
       update_statement := '
       update ' || v_table_name || '
          set n = 2';
    
       execute immediate update_statement;
     end;
     
    

    For more information about the Execute Immediate, please read execute immediate statement.
    For Dynamics, reading SQL statements dynamic SQL Oracle 11 g.

  • A query on bind variables

    Hello

    I have a procedure that takes the deptno parameter and inserts that records departments of the table emp for the new table.

    This code does not exist in a real system. I was trying to understand that the advantage of linking variable.i he wrote in different ways as below
    Create table emp3 as select * from emp where 1=2;
    
    create or replace procedure test1 (p_deptno in number)as 
    begin
     execute immediate 'insert into emp3
                                   select *
                                   from emp
                                   where deptno=:1'
                                   using p_deptno;
    end;
    The works fine.i code above writes the following much too.

    create or replace procedure test2 (p_deptno in number)as 
    begin
     insert into emp3
          select *
          from emp
          where deptno=p_deptno;
    end;
    the first no matter what performance benefit over the second one that is the right way to do it in a real-world system?
    . I could not do a comparison of performance because I don't have access to a currently oracle instance and did it in workshop SQL that comes with Apex.My apology for this...

    Kind regards
    CKLP

    Published by: CKLP on August 29, 2011 03:21

    CKLP wrote:

    the first no matter what performance benefit over the second one that is the right way to do it in a real-world system?

    Not really. Do not forget that all interpreted SQLs winds up as sliders to the sharing of the database Pool.

    If a cursor exists already for a SQL statement, SQL will reuse this slider existing (soft parser). So in a SQL engine perspective, there is no different between the two methods. These statements will be btw generate the same cursor SQL - code SQL of base and bind variable positions are identical.

    From a PL/SQL's point of view, there is a huge difference.

    The first option may be a little slower. Why? There he uses the immediate execution interface which is not as optimized as the implicit cursor to the PL/SQL interface. You use a "heavier" SQL interface in PL/SQL which results in more work for the PL/SQL engine.

    The second option is compiled in an implicit cursor. The SQL code is known, controlled and checked, and compiled PL/SQL code deals with a known SQL statement. Unlike the first option.

    The second option also means that your code will not fail (because SQL syntax errors, etc.) currently running. If this static SQL statement in your code is no longer valid (due to a table being deleted, used column removed, etc.), then your code becomes invalid. With the first option, the code remains valid - and when it is executed, it will throw an exception that the (dynamic) SQL cannot be analyzed and that it is not valid.

    The first option also introduces the spectrum of a SQL injection. Let's say that there is a way to cause a buffer overflow exploit in the database call that executes this procedure. The SQL itself is a string, it is an easy attack vector as the overflow needs that data of type string to inject executable code - as opposed to the p-code or machine code. (an unlikely scenario, but the basic principle of security remains true)

    Dynamic SQL is unnecessary for 99% of the time in PL/SQL. And 99% of the time, with the help of the dynamic SQL is for the wrong reasons, or ignorance or both.

  • Bind variable to modify session commands

    When I tried to run the SQL below, I get an error "SQL error: ORA-02248: invalid option for ALTER SESSION.

    language_setting variable varchar2 (20)
    exec: language_setting: = 'LINGUISTICS '.
    ALTER session set NLS_COMP =: language_setting;

    I also found another link stating that bind variables are not supported for the ddl statements.

    When I try to run this edit query session in Java using a prepared statement, I get a different error that is even more confusing "ORA-01036: illegal variable name/number.

    Given that the error messages are not clear to the State if bind variables are a problem, I would like to know if someone has faced a similar problem.

    Table 1 wrote:
    Thanks for the reply. Can you please provide more details on the above query works and does not have that I mentioned earlier?

    One you mentioned above does not work for precisely the reason that you have identified:

    ORA-01027: bind variable not allowed for data definition operations

    Cause: An attempt was made to use a variable binding in a set of SQL data operation.
    Action: These bind variables are not allowed. >

    A Dbb position works because it uses DYNAMIC SQL statements to build the SQL string, and then run it.

  • IN construction in the clause WHERE of VO with bind variable

    Hello
    With the help of JDev 11.1.1.3.0.
    I have a SQL according to VO following where clause ' WHERE some_nbr IN: inSomeNbrStr'
    -l' some_nbr attribute is of type oracle.jbo.domain.Number.
    -variable binding inSomeNbrStr is of type String.
    I'm assuming that this variable linking parameter to for example. "101, 102' or '(101, 102) ' before the execution of the query might work.
    "However, I get ' ORA-01722: invalid number." Other than the substitution of executeQueryForCollection() and manipulate by program the
    query is - anyone know a more declarative way to achieve this?
    Thank you
    Kenneth

    Hello

    You "MOUNT" the binding variable to get the values separated by commas.

    See this article (Search Using Comma-Separated bind string for the Variable in the list) on how to achieve this.

    It has been developed over 10g. But I think it will hold good for 11g as well.

    Arun-

  • bind variables and dynamic sql

    Hi all

    Here's my situation:

    I have a query with 2 bind variable: the FROM clause also uses a variable binding!

    PROCEDURE describe_columns(p_curr_tablename VARCHAR(50), p_curr_intentseq NUMBER)
       IS
          l_cur     INTEGER;
          l_query   VARCHAR (100);
       BEGIN
          l_query :=
             'select * from :table_name where ibmsnap_intentseq = :sequencenr';
          l_cur := DBMS_SQL.OPEN_CURSOR;
          DBMS_OUTPUT.PUT_LINE (p_curr_tablename);
          DBMS_OUTPUT.PUT_LINE (p_curr_intentseq);
          DBMS_OUTPUT.PUT_LINE (l_query);
          DBMS_SQL.PARSE (l_cur, l_query, DBMS_SQL.V7);
          DBMS_SQL.bind_variable (l_cur, ':table_name', p_curr_tablename);
          DBMS_SQL.bind_variable (l_cur, ':sequencenr', p_curr_intentseq);
          DBMS_SQL.DESCRIBE_COLUMNS (l_cur, g_count, g_desc_tab);
          DBMS_SQL.CLOSE_CURSOR (l_cur);
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line ('DF-EXCEPTION: ' || SQLERRM);
             DBMS_OUTPUT.put_line (
                'DF-EXCEPTION: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
             );
    
             IF DBMS_SQL.IS_OPEN (l_cur)
             THEN
                DBMS_SQL.CLOSE_CURSOR (l_cur);
             END IF;
       --         RAISE;
       END;
    and the output is:
    CD_B136V4_NEW
    16
     select * from :table_name where ibmsnap_intentseq = :intentseq
    DF-EXCEPTION: ORA-00903: invalid table name
    DF-EXCEPTION: ORA-06512: in "SYS.DBMS_SYS_SQL", line 906
    So is the problem that I want to use a variable binding for the name of the table?

    I'd appreciate any help!
    Thank you!

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:227413938857

    Identifiers cannot be used as variable bind - never. Identifiers must be "hard-coded".
    in the query.

    I can't put in a link for "emp" variable because I can't use a string
    constant for emp.

    The reason is quite simple - a bind variable query is parsed and optimized once
    variables are evaluated before linking. If I could code:

    Select * from: bind_x

    the optimzer would not have an idea of what will come with, security (access rights)
    could be evaluated and so on. We could not develop a plan for this query - not
    enough information. Therefore, no variable bind for identifiers.

  • PL/SQL using bind variable to delete records

    Hello

    I'm currently implementing PL/SQL using bind variables to remove records from the "item_progress" table in the simple join query where I'm passing itemName, itemLoc and orderLoc in the delete query in pl/sql block.

    Please suggest, it should be easy for oracle experts...

    (a) I need first records in the item_progress table by using the join query and then update of status in the renew_item table.
    (b) it works fine if I use the simple removal with a condition that is ("DELETE from item_progress where itemname =: 1' using itemname1").

    (c) but it gives an error when I run it using delete with join:
    ---------------------------------------
    * Invalid relational operator ORA-00920:
    ORA-06512: at "SE", line 14 (it's the deletion with the join... "DELETE FROM item_progress WHERE item_id IN (SELECT ip.item_id'...)" ....'
    ORA-06512: at line 10
    Process exited.*
    ---------------------------------------

    create or replace PROCEDURE PUT (itemName IN VARCHAR2,
    itemLoc IN VARCHAR2,
    orderLoc IN VARCHAR2) is
    itemName1 varchar2 (30);
    itemLoc1 varchar2 (30);
    orderLoc1 varchar2 (30);
    BEGIN
    orderLoc1: = ' C: test/local /';
    itemLoc1: = ' / / L123/R;
    itemName1: = 'AAA ';

    immediate execution

    "DELETE FROM item_progress WHERE item_id IN (SELECT ip.item_id FROM ip, item_order io item_progress WHERE io.orderlocation: = 1 AND ip.order_id io.order_id UNION SELECT item_id FROM item_progress WHERE ITEMLOCATION =: = 2) AND itemname: = 3' using orderloc1, itemloc1, itemname1;"

    -"DELETE from item_progress where itemname =: 1' using itemname1; -IT WORKS FINE
    -Once the above query is updated to success, the status in another table
    -Renew_item update the Status value = "RENEWED" where ITEMNAME =: 1, ITEMLOCATION =: 2 using itemname1, itemloc1;

    commit;
    END OPERATIONS;

    user10828299 wrote:
    Please suggest, it should be easy for oracle experts...

    You have made a typo. bind variables are preceded by two points, while you put a colon in front of the equality operator that he listens to it in the PL/SQL assignment operator. Change:

    WHERE io.orderlocation : = 1

    TO

    IO.orderlocation WHERE =:1

    Change:

    WHERE ITEMLOCATION : = 2

    TO:

    WHERE ITEMLOCATION =:2

    Change

    AND itemname : = 3

    TO:

    AND itemname =:3

    SY.

  • Estimate of poor cardinality using Bind Variables

    Hi I'm using the 11.2.0.4.0 Oracle version. I have a query that is underway for the plan of the poor execution by the estimate of poor cardinality for two tables (I've extracted and published this part only) as I mentioned below, the individual conditions for which the estimate goes bad and moving entire query execution path.

    These are for two tables and currently we use BIND variable for them in our code, and I notice, its best estimate gives with literals. I need to know how to handle this scenario that I need this query to execute for all types of volumes. Is there something I can do without changing the code, as it works well for most of the execution? In the current scenario of the main query that uses those below tables providing a plan (index + nested loop) that works very well for small volume, but running for 10 hr + for large volume as ideally its going to the same regime.
    And Yes, most time that this request will be hit for small volume, but killing some appearance of large volume presents the performance of the queries.


    Here are the values of the variable binding.

    B1 VARIABLE VARCHAR2 (32);
    B2 VARIABLE VARCHAR2 (32);
    B3 VARIABLE NUMBER;
    B4 VARIABLE VARCHAR2 (32);
    B7 VARIABLE VARCHAR2 (32);
    B5 VARIABLE NUMBER;
    B6 VARIABLE NUMBER;

    EXEC: B1: = 'NONE ';
    EXEC: B2: = NULL;
    EXEC: B3: = 0;
    EXEC: B4: = NULL;
    EXEC: B7: = NULL;
    EXEC: B5: = 0;
    EXEC: B6: = 0;

    ---- For  TABLE1-------
     -- Published Actual VS Etimated cardinality
     
     
    -- With bind values
    select * from TABLE1 SF
    WHERE (   (SF.C1_IDCODE = :B4) OR (NVL (:B4, 'NONE') = 'NONE'))
        AND ( (SF.C2_ID = :B3) OR (NVL (:B3, 0) = 0));
    Plan hash value: 2590266031
    -----------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                 | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |  OMem |  1Mem | Used-Mem |
    -----------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT          |                     |      1 |        |  28835 |00:00:00.08 |    2748 |     46 |       |       |          |
    |*  1 |  TABLE ACCESS STORAGE FULL| TABLE1              |      1 |     11 |  28835 |00:00:00.08 |    2748 |     46 |  1025K|  1025K|          |
    -----------------------------------------------------------------------------------------------------------------------------------------------
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       1 - storage((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0)))
           filter((("SF"."C1_IDCODE"=:B4 OR NVL(:B4,'NONE')='NONE') AND ("SF"."C2_ID"=:B3 OR NVL(:B3,0)=0))) 
     
    -- With literals 
    select * from TABLE1 SF
     WHERE  (   (SF.C1_IDCODE = null) OR (NVL (null, 'NONE') = 'NONE'))
          AND ( (SF.C2_ID = 0) OR (NVL (0, 0) = 0));
       Plan hash value: 2590266031
    --------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                 | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    --------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT          |                     |      1 |        |  28835 |00:00:00.03 |    2748 |       |       |          |
    |   1 |  TABLE ACCESS STORAGE FULL| TABLE1              |      1 |  28835 |  28835 |00:00:00.03 |    2748 |  1025K|  1025K|          |
    --------------------------------------------------------------------------------------------------------------------------------------
    
    --------For TABLE2 ----------------------- 
    -- Published Autotrace plan, as it was taking long time for completion, and actual cardinality is 45M, but its estimating 49 With bind value---
    
    --withbind value
    select * from TABLE2 MTF
    WHERE (   (MTF.C6_CODE = TRIM (:B2)) OR (NVL (:B2, 'NONE') = 'NONE'))
      AND (   (MTF.C3_CODE = :B1)  OR (NVL (:B1, 'NONE') = 'NONE'))
      AND (   (MTF.C4_CODE = :B7)  OR (:B7 IS NULL))
      AND (   (MTF.C5_AMT <= :B6)  OR (NVL (:B6, 0) = 0))
      AND (   (MTF.C5_AMT >= :B5)  OR (NVL (:B5, 0) = 0));
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1536592532
    -----------------------------------------------------------------------------------------------------------
    | Id  | Operation                  | Name         | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    -----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT           |              |    49 | 10437 |   358K  (1)| 01:11:43 |       |    |
    |   1 |  PARTITION RANGE ALL       |              |    49 | 10437 |   358K  (1)| 01:11:43 |     1 |  2 |
    |*  2 |   TABLE ACCESS STORAGE FULL| TABLE2       |    49 | 10437 |   358K  (1)| 01:11:43 |     1 |  2 |
    -----------------------------------------------------------------------------------------------------------
    Predicate Information (identified by operation id):
    ---------------------------------------------------
       2 - storage(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR
                  NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND
                  ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR
                  NVL(:B2,'NONE')='NONE'))
           filter(("MTF"."C4_CODE"=:B7 OR :B7 IS NULL) AND ("MTF"."C3_CODE"=:B1 OR
                  NVL(:B1,'NONE')='NONE') AND ("MTF"."C5_AMT"<=TO_NUMBER(:B6) OR NVL(:B6,0)=0) AND
                  ("MTF"."C5_AMT">=TO_NUMBER(:B5) OR NVL(:B5,0)=0) AND ("MTF"."C6_CODE"=TRIM(:B2) OR
                  NVL(:B2,'NONE')='NONE'))
      
    -- with literal
    select * from TABLE2 MTF
    WHERE (   (MTF.C6_CODE = TRIM (null)) OR (NVL (null, 'NONE') = 'NONE'))
     AND (   (MTF.C3_CODE = 'NONE') OR (NVL ('NONE', 'NONE') = 'NONE'))
      AND (   (MTF.C4_CODE = null)  OR (null IS NULL))
       AND (   (MTF.C5_AMT <= 0)  OR (NVL (0, 0) = 0))
      AND (   (MTF.C5_AMT >= 0)  OR (NVL (0, 0) = 0));
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1536592532
    -----------------------------------------------------------------------------------------------------------
    | Id  | Operation                  | Name         | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    -----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT           |              |    45M|  9151M|   358K  (1)| 01:11:41 |       |    |
    |   1 |  PARTITION RANGE ALL       |              |    45M|  9151M|   358K  (1)| 01:11:41 |     1 |  2 |
    |   2 |   TABLE ACCESS STORAGE FULL| TABLE2 |    45M|  9151M|   358K  (1)| 01:11:41 |     1 |  2 |
    -----------------------------------------------------------------------------------------------------------
    
    select column_name,num_nulls,num_distinct,density
    from dba_tab_col_statistics where table_name='TABLE2'
    and column_name in ('C3_CODE','C4_CODE','C5_AMT','C6_CODE');
    C3_CODE 0 65 0.0153846153846154
    C4_CODE 0 2 0.5
    C5_AMT 0 21544 4.64166357222429E-5
    C6_CODE 1889955 71 0.0140845070422535
    
    

    933257 wrote:

    ((SF. C1_IDCODE =: B4) OR (NVL (: B4, 'NONE') = 'NONE'))

    In fact for literals, I did not find any section of the predicate after running the sql code with activation "set autotrace traceonly explain."

    The main problem is with another large query whose cardinality is underestimated due to the presence of these table (table1, table2) with the above mentioned clause, and the query is for the analysis of index + nested with values of Bind loops and take 10 hr +, whereas with literals, its completion in ~ 8minutes with FTS + Hash Join.

    Your real problem is that you try to have just a single SQL query handle all POSSIBLE thanks to the use of embedded FILTERS ' either / or ' filters in the WHERE clause.  You want only a select this OPTION to run whatever filters have been selected at run time by the user or the application using it.  And it would never work.  You really need to SELECT different queries for different combinations of filter conditions.

    Why?  Think for a minute.  How Oracle works internally?  A SQL SELECT query gets analyzed and an execution plan is produced which is stored in the library cache and gets REUSED on all subsequent executions of this query - except in certain cases where there may exist several plans run through several cursors of the child.  So with only SELECT a query you only AN execution plan in the library cache, to be used by all THE executions of this query, regardless of the value of your run-time binding variables.

    Lets put another way - each library cache execution plan is associated with a SQL statement.  If you want a DIFFERENT execution plan then you need run a DIFFERENT SQL statement.  That's how you get a different execution plan - by running a different SQL statement.  Running the SAME SQL query generally you will get the SAME execution plan every time.

    In addition, because of the "either / or" filters that you use you will end up generally with a full Table Scan on each of the referenced tables.  Why?  Given that the optimizer must produce an implementation plan that manages all possible contingencies for all values of possible bind variables in the SELECT.  If the optimizer should choose to use any index based on one of these "either / or" filters then it would only help performance when real value was provided, but it would be really bad if a NULL value was supplied.  If the optimizer ends up ignoring the index because they are not always optimal for all possible input values and instead chose a plan that is "good enough" for all input values possible.  That means that it will use a scanning Table full.

    I hope you can see that it is precisely what is happening for you with your query.  You select this OPTION to manage the different combinations of filter, which leads to the execution plan only one, which leads to scans full Table on the referenced tables in these ' either / or ' filters.

    The solution?  Build queries SELECT DIFFERENT when input values are NULL.  How you do that?  Read this article to ask Tom that tells you:

    http://www.Oracle.com/technetwork/issue-archive/2009/09-Jul/o49asktom-090487.html

    To sum up - when you have real value for a bind variable 'bind_var1' add the following filter to your CHOICE:

    AND column_name1 =: bind_var1

    When the binding variable is NULL, add the filter according to your CHOICE:

    AND (1 = 1 OR: bind_var1 IS NULL)

    Now, you'll have 2 queries SELECT must be performed, which have exactly the same number of variables in the same order bind, which is important.  When you then run one of these variations, Oracle can analyze and optimize each one SEPARATELY, with a single execution by the SELECT query plan.

    When you provide a real value, the filter is a normal 'column = value' that the optimizer can use all indexes on this column, because NULL values are not referenced.

    When there is no real value, the optimizer will analyze the '1 = 1 GOLD' and realize that "1 = 1" is set to TRUE and GOLD, it is quite TRUE regardless because the binding variable is null or not.  This means that the optimizer will actually REMOVE this filter, because it filters nothing because it is always TRUE.  You will end up with an operating plan based on the other filters in the query, which is what you want because you have no filter on this column.

    What is it - producing distinct SELECT queries to determine if you have a real value to filter or not you end up with DIFFERENT execution plans for each of them, and each of them is OPTIMAL for this particular set of filters.  Now you get good performance for each variation of the performance of the SELECTION, rather than sometimes good and sometimes very bad when using SELECT only one.  It is impossible to try to get multiple shots of execution 'optimal' out of a SELECT query.  That's why you get mediocre performance under different bound the values of the variables.

    John Brady

  • Estimates of cardinality for index range scan with bind variables

    Oracle 11.2.0.4

    I am struggling to explain that the cardinality estimates for a scan of the index systematic range when using the bind variable.

    Consider the following query:

    SELECT /*+ INDEX(t1) */ *
    FROM   t1
    WHERE  source_id <= ?;
    
    

    Cardinalities for the INDEX RANGE SCAN and ACCESS of the TABLE are the same for different literal predicates, for example, source_id < = 5:

    ------------------------------------------------------------------------------------
    | Id  | Operation                   | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |      |    50 |   350 |    12   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T1   |    50 |   350 |    12   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IX1  |    50 |       |     2   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("SOURCE_ID"<=5)
    
    

    If a variable binding is used instead of a literal, the overall selectivity is 5%. However, why the optimizer based on CSSTidy gives a cardinality estimated 11 for the scan of the index systematic range? As with the predicates literal, surely the cardinalities of the index range scan and access table should be the same?

    ------------------------------------------------------------------------------------
    | Id  | Operation                   | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |      |    50 |   350 |     5   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T1   |    50 |   350 |     5   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IX1  |    11 |       |     2   (0)| 00:00:01 |
    ------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("SOURCE_ID"<=TO_NUMBER(:A))
    
    

    Unit test code:

    CREATE TABLE t1
    ( id NUMBER
    , source_id NUMBER
    );
    
    CREATE INDEX ix1 ON t1 (source_id);
    
    INSERT INTO t1
    SELECT level
         , ora_hash(level,99)+1
    FROM   dual
    CONNECT BY level <= 1000;
    
    exec DBMS_STATS.GATHER_TABLE_STATS(user,'T1')
    
    EXPLAIN PLAN FOR
    SELECT /*+ INDEX(t1) */ *
    FROM   t1
    WHERE  source_id <= 5;
    SELECT * FROM TABLE(dbms_xplan.display);
    
    EXPLAIN PLAN FOR
    SELECT /*+ INDEX(t1) */ *
    FROM   t1
    WHERE  source_id <= :a;
    SELECT * FROM TABLE(dbms_xplan.display);
    
    

    There are various places where the optimizer uses an assumption, and lie unpeekable (and of Villa "unknowable value") introduced guess.

    For unpeekable binds the conjecture for column<= {unknown}="" is="" 5%="" for="" table="" access="" (hence="" 50="" rows="" out="" of="" 1,000),="" but="" it's="" 0.009="" for="" index_column=""><= {unknown},="" which="" means="" i="" was="" expecting="" to="" see="" 9="" as="" the="" row="" estimate="" on="" the="" index="" range="">

    I just ran some quick tests, and EXPLAIN the PLAN seems to just use 0.011 selectivity in this case (in different versions of Oracle) although if we do the bind variable unpeekable at run time (and sample dynamic block etc.) optimization for execution is 0.009%.

    Concerning

    Jonathan Lewis

    Update: and this is a very old reference to the 0.009 (and 0.0045 for ' between the ' when it is applied to a clue: cost based Oracle - access Chapter 4 single B-tree )

  • Bind Variables on the view objects child definition

    JDeveloper 12 c

    I have an interesting question.  I have a view (AisWebModulePrivsVO) object that uses a bindvariable hardcoded in the view object.

    SELECT * FROM SYS. DBA_ROLE_PRIVS where DEALER =: bvUserName

    If I put this in the request module I can programmatically set the variable binding (view object contains the getter/setter for the binding variable).

    AisWebModulePrivsVOImpl voTest = am.getAisWebModulePrivsVI ();

    voTest.setbvUserName ("ARAWLS");

    voTest.executeQuery ();

    System.out.println ("test reports:" + voTest.getRowCount ());

    and get the correct number of records based on return on the user and database roles. If it works.

    What does NOT work, it is when this display object is a recording of 'the child' to another display object (as specified by a link between the two and by setting the object from a point of view as one child of the other in the module of the application).

    AppModule looks like this:

    CgRefCodesVO

    AisWebModulePrivsVO

    In this case, I have a view called cgRefCodeVO parent object.  There is a link between this and the AisWebModulePrivsVO. The relationship works.

    AISMenuAppModuleImpl m = ADFUtils.getApplicationModuleForDataControl (appMod) (AISMenuAppModuleImpl);

    CgRefCodesVOImpl cgRefVO = am.getCgRefCodes1 ();

    AisWebModulePrivsVOImpl modsVO = am.getAisWebModulePrivs1 ();

    modsVO.setbvDBUserName ("ARAWLS");  This doesn't seem to work here...

    cgRefVO.executeQuery ();

    All lines rs = cgRefVO.getRowSet ();

    RS. Reset();

    While (rs.hasNext ()) {}

    CgRefCodesVORowImpl CgRefRow = rs.next ((CgRefCodesVORowImpl));

    System.out.println ("RvLowValue:" + CgRefRow.getAttribute ("RvLowValue"));

    RowIterator aisModulesRowIter = CgRefRow.getAisWebModulePrivs ();

    System.out.println ("number of children:" + aisModulesRowIter.getRowCount ());

    }

    The code compiles and runs.  She translates: "County of the child: 0" for each row returned by the

    I also tried:

    VM VariableValueManager = modsVO.ensureVariableManager ();

    vm.setVariableValue ("bvDBUserName", "ARAWLS");

    And:

    modsVO.setNamedWhereClauseParam ("bvDBUserName", "ARAWLS");

    and (of https://community.oracle.com/message/2746551#2746551 ( )

    @Override

    protected void executeQueryForCollection (Object, object, Object [] object2, int i) {}

    I coded everything hard to see if it would work.

    setNamedWhereClauseParam ("bvDBUserName", "ARAWLS");

    super.executeQueryForCollection (object, object2, i);

    }

    and from there, I changed around the order to execute the objects in view.    https://community.oracle.com/message/10632314#10632314

    How can I set the variable binding in the object view child?

    Thank you

    Stuart

    It is an interesting example how ADF works up to a certain point... then you need to start to make cuts to modify its behavior as you wish.

    I decided that it was just easier to delete 'the child' parent (in the app module) and create a view of criteria on this subject for what would basically query the records to get the same results, like a child.

    Perhaps not as elegant, but so much easier.

    Thanks for your help.

    Stuart

  • SQL * more substitution vs bind variable question

    Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...

    example:

    create table blah as

    Select * from table

    WHERE DATE between start_date and END_DAY;

    the DATE is a numeric field, YYYYMMDD

    The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.

    The END_DAY is * always * last Friday and I realized that:

    variable L_FRIDAY char (15);

    Start

    Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;

    end;

    /

    The thing is that I get an error when I try to use the binding variable?

    create table blah as

    Select * from table

    WHERE DATE between start_date and: L_FRIDAY;

    Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...

    When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?

    Help!

    :-)

    Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables

    I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.

    Hello

    Kodiak_Seattle wrote:

    Hi all, I am trying to automate some SQL within SQL codes * more script that is triggered by a script .bat, the only parts that change are Dates...

    example:

    create table blah as

    Select * from table

    WHERE DATE between start_date and END_DAY;

    the DATE is a numeric field, YYYYMMDD

    The script runs always at the beginning of a new week, so a Monday, unless a public holiday, then a Tuesday.

    The END_DAY is * always * last Friday and I realized that:

    variable L_FRIDAY char (15);

    Start

    Select to_char (next_day(sysdate-7,'FRIDAY'), 'YYYYMMDD') as Last_Friday in: double L_FRIDAY;

    end;

    /

    The thing is that I get an error when I try to use the binding variable?

    create table blah as

    Select * from table

    WHERE DATE between start_date and: L_FRIDAY;

    Then once I found the end date, I was going to use add_months(L_FRIDAY,-12) for previous 12 months for the start_date...

    When I tried to use a variable Substitution I could just hard code the date, but I can not or do not know how to set the value of this exec to the variable?

    Help!

    :-)

    Basically my research reveals that - Bind variables are not allowed for operations of data definition, use substutions instead of bind variables

    I need an automated way to find the END_DAY which is last Friday and START_DATE that is 12 months before Friday and refer to those in the SQL without errors.

    Or SQL * more bind variable or variable substitution can be DATEs.  The best you can do is set a different type, as a string, representing a date.  A string as June 19, 2015"represents a date, but so strings like 'SYSDATE' and ' SYSDATE - 7', so you can do something like this:

    SET l_friday = ' NEXT_DAY ((SYSDATE-7), 'FRIDAY').

    DEFINE start_date = "ADD_MONTHS (& l_friday, - 12)"

    SELECT & start_date AS t_n

    , & l_friday AS l_f

    OF the double

    ;

    Output (when executed on 25 June 2015):

    L_F T_N

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

    June 19, 2014 19 June 2015

  • R12 Extension with bind variables-how VO EO

    Hello

    I extended an APInvDistAllVO view object by adding two fields which are functions. Basically, in the invoice approval screen, I want to add two fields where the distribution of the invoice is shown.

    the SQL contained in jdeveloper when you extend the VO object is different from the query, what I see in the invoice approval page by clicking on the APInvDistAllVO link. There are two bind variable: 1 = invoice_id and: 2 = line_number being added dynamically.

    After the extension of the view object, the invoice distribution line is displayed as no record found. In my opinion, it is due to not having bind variables does not correct parameters being passed, and under this point of view object is an object depending on the invoice header record.

    Will be very grateful if someone can provide the way forward in dealing with this situation.

    Rgds

    Fahad

    User, please ask your question in the forum OA Framework .

    Timo

  • EO base extension VO with bind variables and display - How To link

    Hello

    I extended an APInvDistAllVO view object by adding two fields which are functions. Basically, in the invoice approval screen, I want to add two fields where the distribution of the invoice is shown.

    The SQL contained in jdeveloper when you extend the VO object is different from the query, what I see in the invoice approval page by clicking on the APInvDistAllVO link. There are two bind variable: 1 = invoice_id and: 2 = line_number being added dynamically. After the extension of the view object, the invoice distribution line is displayed as no record found.

    In my opinion, it is due to not having bind variables does not correct parameters being passed, and under this point of view object is an object depending on the invoice header record. There is a link to the original View object as well. Will be very grateful if someone can provide the way forward in dealing with this situation.

    Rgds Fahad

    Hi AJ

    He worked after changing the style of bind.

    Thank you very much.

    Rgds

    Fahad

  • Passing literal as a bind variable in Jena

    Hi all

    We are able to use bind variable with the id RDFVID. However, if we want to check for a literal using the jena/joseki adapter we are not able to perform the same operation. In our case the literal is of type string.

    We use:

    * WLS 12.1.0.3.

    * Adapter Jena 2.11.1.

    * Joseki 3.4.4.

    * ARQ 2.9.2.

    We try to run the following query on the stop of joseki.

    PREFIX foaf: http://xmlns.com/FOAF/0.1/ >

    PREFIX vcard: http://www.w3.org/2001/vCard-RDF/3.0# >

    PREFIX xsd: http://www.w3.org/2001/XMLSchema# >

    PREFIX oext: < http://Oracle.com/Semtech/Jena-adaptor/ext/function# >

    PREFIX ORACLE_SEM_FS_NS: http://Oracle.com/Semtech#no_fall_back, ALLOW_DUP = T, s2s >

    PREFIX ORACLE_SEM_HT_NS: http://Oracle.com/Semtech#monitor >

    PREFIX ORACLE_SEM_UEAP_NS: http://oracle.com/semtech#f$ RDFVID % 20 (ORACLE_ORARDF_RES2VID(?)) >

    PREFIX ORACLE_SEM_UEPJ_NS: http://Oracle.com/Semtech#f $RDFVID >

    PREFIX ORACLE_SEM_UEBV_NS: http://Oracle.com/Semtech# 'Lee' >

    SELECT? f

    WHERE

    {graph? g {? vcard:N p? vn.}}

    ? VN vcard:Family? f.

    ? FOAF:title p 'Sen'.}

    }

    The result set is empty. Replace the line 'ORACLE_SEM_UEBV_NS PREFIX: <http://oracle.com/semtech# "Lee"> "by any Variant is to be given an error or the empty set. (Some variants (& quot;)) Lee & quot; Lee, "Lee" & #39; Lee & #39; )

    When we use the generated SQL code of jena/joseki, we are able to get the right result if we execute the query even in SQLDeveloper. To use the variable binding is "Lee" (the binding variable is the price included). This will give you a correct result in withdrawal.

    Kind regards

    Max

    Hi Max,.

    In the area of the UEBV, you must put "Lee" encoded in URL string

    Please, try the following and see if it helps.

    % 22Lee % 22

    Thank you

    Zhe Wu

  • Bind variables in SPARQL WLS jena queries

    Hi all

    We read about the possibilities of support of jena to bind the variables in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#RDFRM248). The problem has been addressed in the next section on 14 June 2014 (Bind Variables in SPARQL queries). However, we are facing other problems.

    We use:

    * WLS 12.1.3.0.0

    * adapter jena 2.11.1.

    * Joseki 3.4.4.

    * ARQ 2.9.2.

    We try to run the following query on the stop of joseki.

    PREFIX foaf: http://xmlns.com/FOAF/0.1/ >

    PREFIX vcard: http://www.w3.org/2001/vCard-RDF/3.0# >

    PREFIX ORACLE_SEM_FS_NS: http://Oracle.com/Semtech#no_fall_back, ODS = 6, ALLOW_DUP = T, s2s >

    PREFIX ORACLE_SEM_HT_NS: http://Oracle.com/Semtech#monitor >

    PREFIX ORACLE_SEM_UEAP_NS: http://Oracle.com/Semtech#f$ RDFVID % 20 to (?) >

    PREFIX ORACLE_SEM_UEPJ_NS: http://Oracle.com/Semtech#f $RDFVID >

    PREFIX ORACLE_SEM_UEBV_NS: http://Oracle.com/Semtech#1264839720472151591 >

    SELECT? f? g

    WHERE

    {graph? g {? vcard:N p? vn.}}

    ? VN vcard:Family? f.

    ? FOAF:title p 'Sen'.}

    }

    However, the result that we get back does not use the variable binding. It returns the entire list without UEAP/UEPJ/UEBV.

    Is there something that I missed in the documentation or should I define some variables for the use of bind variables?

    Kind regards

    Max

    Hi Max,.

    Can you please define the following JVM property to the WLS and restart the middle range?

    -Doracle.spatial.rdf.client.jena.allowAP = true

    This configuration is only necessary when running a variable binding based SPARQL query from a web service endpoint.

    Let me know if this can help,

    Zhe Wu

Maybe you are looking for