ORA-01006: there is no bind variable

Hello

I'm trying to shoot an insert that inserts data into a table from another table based on certain conditions.
But I get this error.
declare
v_c1 varchar2(10):='a1';
date_c2 varchar2(15):='12-aug-2012';
begin
strquery:='insert into tab1 select from tab2 where tab2.c1='':x'' and tab2.c2='':y''';
execute immediate strquery using v_c1,date_c2; ------------BIND VARIABLE date_c2 does not exist
end;

Review your dynamic sql code:

SQL> set serveroutput on
SQL> exec dbms_output.put_line('insert into tab1 select from tab2 where tab2.c1='':x'' and tab2.c2='':y''');
insert into tab1 select from tab2 where tab2.c1=':x' and tab2.c2=':y'

PL/SQL procedure successfully completed.

SQL> 

Can't you see you just bind variables? All I see are strings ": X"and": there '." Change:

 strquery:='insert into tab1 select from tab2 where tab2.c1='':x'' and tab2.c2='':y''';

TO

strQuery: ='insert into select tab1 tab2 where tab2.c1 =: x and tab2.c2 =: y';

SY.

Tags: Database

Similar Questions

  • on the ora-01006: there is no bind variable

    Hi all of you, I have this dynamic sql code:

    DECLARE

    CLOB v_query;

    number of CPT;

    Start

    v_query: ='

    SELECT

    County (TBA. ANT_ID)

    Of

    ...

    WHERE TBA. ANT_FUT_ID = TFT. FUT_ID

    AND TBA. ANT_KATEGORIE_CODE_ID = TAKCL. ANT_KATEGORIE_CODE_ID (+)

    AND TBA. ANT_KFZ_REIHEN_ID = TKR. KFZ_REIHEN_ID (+)

    AND TBA. ANT_ID = F1. ANT_ANT_ID (+)

    AND TBA. ANT_ID = F2. ANT_ANT_ID (+)

    AND TBA. ANT_ID = F3. ANT_ANT_ID (+)

    AND TBA. ANT_ID = ERS.ers_bdk (+)

    AND TBA. ANT_ID = F1_2.ANT_ANT_ID (+)

    AND TBA. ANT_ID = F2_3.ANT_ANT_ID (+)

    AND TBA. ANT_ID = UPM. MFU_ANT_ID (+)

    AND UPM. MFU_NIETGEOMETRIE_ID = NG. NG_ID (+)

    AND UPM. MFU_MATRIZEN_BEICHNUNG_ID = MZB. MZB_ID (+)

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

    -Suchkriterien: -.

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

    -Creator

    AND DECODE (ERS.ers_id, NULL, '%', ERS.ers_name) AS DECODE (": 1", "%", "') |" ' || :1 ||''''|| DECODE('':1'',''%'',''')

    -Fahrzeug

    AND DECODE (TKR.NAME, NULL, '%', TKR.NAME) AS DECODE (": 2", "%", "') |" ' || :2 ||''''|| DECODE('':2'',''%'',''')

    -BDK

    AND DECODE (fuege_db.bdk_nummer (TBA. ANT_ID, "."), NULL, "PERCENT",

    fuege_db.bdk_nummer (TBA. ANT_ID, ".") ) LIKE '%'. :3||'' %''

    -Technology

    AND TBA. ANT_FUT_ID AS DECODE (": 4%","","') |" ' || :4 ||''''|| DECODE('':4'',''%'',''')

    -Art

    AND ((TBA. ANT_WFP_ID is null and 1 = DECODE('':5'',NULL,1,1,1)) ou (TBA.)) ANT_WFP_ID is not null and 2 = DECODE (": 5 cm, 2,2,2)))

    -ADV

    AND TBA. ANT_VTA = decode (cm: 6 cm, 1.1, TBA.) ANT_VTA) ';

    run immediately v_query

    in USING cpt

    "Dominik Hussmann."

    "AU736_Q7_SUV,"

    '' ,

    "WPS Stahl."

    '',

    '0' ;

    end;

    In execution, I have this error: ora-01006: bind variable does not exist, after analysis, I found that the problem is with the settings: 5 and: 6, I do not understand that they have the same syntax

    as variables bind 1,2,3 and 4.

    Than you for any suggestion.

    I hope that you realize that there are 13 variable bind in your sql, not 6?

    Variables are related by mail. You cannot use the same variable to link twice, they will be 2 separate bind variable.

    For example, you use: 1 three times, so you must provide three arguments, in this case, three times the same value.

  • java.sql.SQLSyntaxErrorException: ORA-01745: host not valid/bind variable nam

    String sequnceDocumentId = "SELECT snw_doc_type_map_id_seq. NEXTVAL INTO: 1 FROM DUAL; " ;

    PreparedStatement pStmt = null;
    ResultSet rs = null;
    rowExists Boolean = false;
    CallableStatement st1 = getDBTransaction () .createCallableStatement (sequnceDocumentId, 1);
    try {}

    ST1.registerOutParameter(1,types.) Integer);
    ST1. ExecuteQuery();
    SeqId number = new Number (st1.getInt (1));
    setDocumentTypeId (seqId);
    ST1. Close();


    }
    catch (Exception e) {}

    e.printStackTrace ();

    }

    Get the following exception

    at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1035)
    at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:191)
    at oracle.jdbc.driver.T4CCallableStatement.executeForDescribe(T4CCallableStatement.java:788)
    at oracle.jdbc.driver.T4CCallableStatement.executeMaybeDescribe(T4CCallableStatement.java:863)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1187)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3386)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3430)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
    at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:128)
    at oracle.apps.snw.schema.server.SnwDocumentTypeMappingsEOImpl.create(SnwDocumentTypeMappingsEOImpl.java:42)


    Please let me know what Miss me...

    Thank you

    Just talking about the top of my head, since I have not tried, but...

    When you use the INTO clause, you are implying that you run in a 3GL environment, in this case, PL/SQL. But if it comes to PL/SQL, you have a BEGIN and END around all the instructions. You must have:

    String sequnceDocumentId ="BEGIN SELECT snw_doc_type_map_id_seq.NEXTVAL INTO :1 FROM DUAL; END;" ;
    
  • 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

  • Oracle.ManagedDataAccess gives ORA-01006 if there is bind variables in the comments, but only on the lines.

    When I go from ODP.NET to the ODP.NET managed some of my questions begins to throw errors missing bind variable.

    I reproduced with a simple example that uses a variable called liaison: unitName

    It's the example SQL:

    SELECT

    : unitName

    Of

    DOUBLE

    Now, if I add a comment at the beginning of the SQL like this:

    -Text with: unitName

    SELECT

    : unitName

    Of

    DOUBLE

    It works, but if I have a variable binding in a comment that is located on a number of the 'same' line, I get ORA-01006:

    This causes the error:

    -First line comment

    -Text with: unitName

    SELECT

    : unitName

    Of

    DOUBLE

    Kind regards

    -Tommy

    I was able to reproduce this problem. I filed Bug 19433348 on your behalf.

    The circumstances in which the bug occurs are fairly easy to get around.

    (1) remove the colon in the second commented line.

    (2) add a space between the '\n' and ' - '.

    If you are one of those things, you won't encounter the bug behavior.

  • is there an order to the bind variable in v$ SQLTEXT_WITH_NEWLINES?

    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for HPUX: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    create and populate the table
    CREATE TABLE mytable
    (
       seq_cd   NUMBER (6) PRIMARY KEY,
       col1     VARCHAR2 (10),
       col2     VARCHAR2 (10),
       col3     VARCHAR2 (10),
       col4     VARCHAR2 (10),
       col5     VARCHAR2 (10),
       col6     VARCHAR2 (10)
    );
    
    INSERT INTO mytable (seq_cd,
                         col1,
                         col2,
                         col3,
                         col4,
                         col5,
                         col6)
         VALUES (1,
                 'one',
                 'two',
                 'three',
                 'four',
                 'five',
                 'six');
    I want to know if there is a consistent order of how bind variables are placed in v$ SQLTEXT_WITH_NEWLINES is always last in first out?
    DECLARE
       mybindvariablelist   SYS.odcivarchar2list;
       vseq_cd              NUMBER (6) := 1;
       vcol1                VARCHAR2 (10) := 'one';
       vcol2                VARCHAR2 (10) := 'two';
       vcol3                VARCHAR2 (10) := 'three';
       vcol4                VARCHAR2 (10) := 'four';
       vcol5                VARCHAR2 (10) := 'five';
       vcol6                VARCHAR2 (10) := 'six';
    BEGIN
       mybindvariablelist :=
          sys.odcivarchar2list (vseq_cd,
                                vcol1,
                                vcol2,
                                vcol3,
                                vcol4,
                                vcol5,
                                vcol6);
    
       INSERT INTO mytable (seq_cd,
                            col1,
                            col2,
                            col3,
                            col4,
                            col5,
                            col6)
            VALUES (vseq_cd,
                    vcol1,
                    vcol2,
                    vcol3,
                    vcol4,
                    vcol5,
                    vcol6);
    EXCEPTION
       WHEN OTHERS
       THEN
          DECLARE
             TYPE sess_data IS RECORD
             (
                curr_sqladd   RAW (8),
                curr_sqlid    VARCHAR2 (20),
                prev_sqladd   RAW (8),
                prev_sqlid    VARCHAR2 (20)
             );
    
             sess_info   sess_data;
             sess        VARCHAR2 (100) := USERENV ('SESSIONID');
             idx         PLS_INTEGER;
          BEGIN
             DBMS_OUTPUT.put_line (SQLERRM || ' when executing ');
    
             SELECT sql_address,
                    sql_id,
                    prev_sql_addr,
                    prev_sql_id
               INTO sess_info
               FROM v$session
              WHERE audsid = sess;
    
             FOR cur IN (  SELECT sql_text
                             FROM v$SQLTEXT_WITH_NEWLINES
                            WHERE address = sess_info.prev_sqladd
                         ORDER BY piece ASC)
             LOOP
                DBMS_OUTPUT.put_line (cur.sql_text);
             END LOOP;
    
             idx := mybindvariablelist.FIRST;
    
             WHILE (idx IS NOT NULL)
             LOOP
                DBMS_OUTPUT.put_line (
                   ':B' || idx || ' = ' || mybindvariablelist (idx));
                idx := mybindvariablelist.NEXT (idx);
             END LOOP;
          END;
    END;
    results in
    ORA-00001: unique constraint (DSAMSTRC.SYS_C0093919) violated when exeduting 
    INSERT INTO MYTABLE (SEQ_CD, COL1, COL2, COL3, COL4, COL5, COL6)
     VALUES (:B7 , :B6 , :B5 , :B4 , :B3 , :B2 , :B1 )
    :B1 = 1
    :B2 = one
    :B3 = two
    :B4 = three
    :B5 = four
    :B6 = five
    :B7 = six
    so as you can see from the output of the order of the table v$ and order, I entered bind variables are reversed. Is this always the case or it is not consistent?

    Pollywog wrote:
    so as you can see from the output of the order of the table v$ and order, I entered bind variables are reversed. Is this always the case or it is not consistent?

    I guess it's just a matter of curiosity, right? All that matters is to connect the variable ends up in a good position. Anyway, as far as I KNOW, Oracle creates a bind variable in the order, and therefore depends on the analysis from left to right or from right to left. And we don't know how to change the order in the different versions of Oracle.

    SY.

  • Bind Variables and using the keyword

    In my dynamic SQL, I use the same variable in several places in my query. Is there a way to avoid rewriting the same value multiple times in the list of arguments to bind? It is something like that - only pseudo code.
    DECLARE
    tSQL VARCHAR2(99)
    pVal INT := 2;
    
    BEGIN
    tSQL := 
               'SELECT * ' ||
               '  FROM dual ' ||
               ' WHERE col1 =: iVal ' ||
               '   AND col2 IN (SELECT col2 ' ||
               '                  FROM dual  ' ||
               '                 WHERE col1 =: iVal) ' ||
               ' UNION ' ||
               ' SELECT * ' ||
               '   FROM dual ' ||
               '  WHERE col1 =: iVal';
    
    EXECUTE IMMEDIATE tSQL 
    USING pVal, pVal, pVal;  -- Is there a way to avoid having to rewrite the same bind variable argument three times since the value is the same?
    
    END;
    Is there a way to avoid having to rewrite the same argument three times bind variable as the value is the same?

    Etbin wrote:
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/dynamic.htm#BHCHIHEJ says:
    Placeholders are associated with bind variable in the USING clause of position, and not by name.

    Concerning

    Etbin

    The exception to this rule is if the SQL statement is an anonymous block or a call statement. In this case, the repetition of the names of the placeholder is significant.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e25519/dynamic.htm#CHDFHEAG

    For example, the following will fail with ORA-01008: not all variables

    declare
     v_cnt number;
    begin
      execute immediate 'select count(*) from dual where 1 = :B1 and 2 > :B1'
      into v_cnt using 1;
      dbms_output.put_line(v_cnt);
    end;
    

    However, the following will succeed because the SQL code is in fact an anonymous block:

    begin
      execute immediate 'declare
                           v_cnt number;
                         begin
                           select count(*)
                           into v_cnt
                           from dual
                           where 1 = :B1 and 2 > :B1;
                           dbms_output.put_line(v_cnt);
                         end;'
      using 1;
    end;
    

    Pretty cool stuff.

  • The use of bind variables with XMLTABLE?

    I tried to use bind variables with xmltable statement. Here, my unit test:

    create or replace function wsdltest return xmltype as
    l_dummy xmltype.
    CLOB l_stt;
    L_Name varchar2 (500);
    CLOB l_xml;
    BEGIN
    l_xml: =.
    ' < name of definitions = 'F1' targetNamespace = "http://xmlns.oracle.com/orawsv/XFILES/F1" xmlns = "http://schemas.xmlsoap.org/wsdl/" xmlns:tns = "http://xmlns.oracle.com/orawsv/XFILES/F1" container = "http://www.w3.org/2001/XMLSchema" xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/" >
    < types >
    < xsd: Schema targetNamespace = "http://xmlns.oracle.com/orawsv/XFILES/F1" elementFormDefault = "qualified" >
    < xsd: element name = "SVARCHAR2-F1Input" >
    < xsd: complexType >
    < xsd: SEQUENCE >
    < xsd: element name = "A VARCHAR2 IN" type = "xsd: String" / >
    < / xsd: SEQUENCE >
    < / xsd: complexType >
    < / xsd: element >
    < xsd: element name = "F1Output" >
    < xsd: complexType >
    < xsd: SEQUENCE >
    < xsd: element name = "RETURN" type = "xsd: String" / >
    < / xsd: SEQUENCE >
    < / xsd: complexType >
    < / xsd: element >
    < / xsd: Schema >
    < / types >
    < name of message = "F1InputMessage" >
    < name of part = "parameters" element = "tns:SVARCHAR2 - F1Input" / >
    < / message >
    < name of message = "F1OutputMessage" >
    < name of part = "parameters" element = "tns:F1Output" / >
    < / message >
    < portType name = "F1PortType" >
    < operation name = "F1" >
    < input message = "tns:F1InputMessage" / >
    < output message = "tns:F1OutputMessage" / >
    < / operation >
    < / portType >
    < connection name = "F1Binding" type = "tns:F1PortType" >
    < style: binding soap = transport "document" = "http://schemas.xmlsoap.org/soap/http" / >
    < operation name = "F1" >
    < soap: operation soapAction = "F1" / >
    < input >
    < soap body parts: = 'settings' use = "literal" / >
    < / Entry >
    < output >
    < soap body parts: = 'settings' use = "literal" / >
    < / output >
    < / operation >
    < / binding >
    < service name = "F1Service" >
    < documentation > Oracle Web Service < / documentation >
    < name of port = "F1Port" binding = "tns:F1Binding" >
    < soap: address location = "http://localhost: 8080/orawsv/XFILES/F1" / >
    < / port >
    < / service >
    < / definitions > ';

    -OK
    l_stt: = ' select * from xmltable (XMLNAMESPACES ("http://www.w3.org/2001/XMLSchema" AS "XSD", default "http://schemas.xmlsoap.org/wsdl/"),)
    [' / / definitions/types/XSD:schema/XSD:element[@name="SVARCHAR2-F1Input ']"
    by the way xmltype(:1)
    columns
    path of xmltype AB ".") you;
    --
    EXECUTE IMMEDIATE l_stt INTO l_dummy using l_xml;

    -ERROR ORA-01006
    L_Name: = ' 'SVARCHAR2-F1Input "";
    l_stt: = ' select * from xmltable (XMLNAMESPACES ("http://www.w3.org/2001/XMLSchema" AS "XSD", default "http://schemas.xmlsoap.org/wsdl/"),)
    [/ / definitions/types/XSD:schema/XSD:element[@name=:2] "
    by the way xmltype(:1)
    columns
    path of xmltype AB ".") you;
    --
    EXECUTE IMMEDIATE l_stt INTO l_dummy using l_xml, l_name;

    Return l_dummy;
    END;

    Any idea?

    Thanks in advance
    Cyryl

    You can try something like

    declare
      l_dummy xmltype;
      l_stt clob;
      l_name varchar2(500);
      l_xml clob;
    BEGIN
    l_xml :=
    '
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    Oracle Web Service
    
    
    
    
    ';
    l_stt := q'~ select *
      from xmltable( XMLNAMESPACES( 'http://www.w3.org/2001/XMLSchema' AS "XSD", default 'http://schemas.xmlsoap.org/wsdl/'),
                   '/definitions/types/XSD:schema/XSD:element'
                   passing xmltype( :2 )
                   columns
                   ab xmltype path '.' ) t
         where extractvalue( ab, '/element/@name', 'xmlns="http://www.w3.org/2001/XMLSchema"' ) = :1
     ~';
    l_name := 'SVARCHAR2-F1Input';
      EXECUTE IMMEDIATE to_char( l_stt ) INTO l_dummy using l_xml, l_name;
      dbms_output.put_line( l_dummy.getstringval() );
    end;
    /
    
  • 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

  • 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

  • Bind variables and dates

    I am writing a process to delete records based on dates.

    Here is the chart:

    Column name Data type Nullable Default Primary key
    IDNUMBERNO.-1
    CT_NAMEVARCHAR2 (100)Yes--
    CT_CATEGORYVARCHAR2 (100)Yes--
    BASE_PTSNUMBERYes--
    PROD_PTSNUMBERYes--
    REF_PTSNUMBERYes--
    START_DATEDATEYes--
    END_DATEDATEYes--
    CREATED_ONDATEYes--
    CREATED_BYVARCHAR2 (50)Yes--
    UPDATED_ONDATEYes--
    UPDATED_BYVARCHAR2 (50)Yes--

    start_date and end_date are the fields of date key.

    The query will remove the dates with specific start and end dates.  The question I have, is that I get a ORA-01858: a non-digit character was found here where was waiting for a digital error while the query is running.

    remove from ct_point_values

    where start_date =: P4_START_DATE_V

    and end_date =: P4_END_DATE_V

    If I run the query in the sql window, no problem:

    remove from ct_point_values

    where start_date =' 01 / 01/2014 '

    and end_date = 31 December 2014"

    Find the query with the works of values hard-coded.  Links to fail.  I tried casting and to_char to_date variations with no luck.

    One thing that I notice, is that when I go to enter my bind variables in the sql workshop, the fields are pre-populated with this:

    1 & amp; #x2F 1 & amp; #x2F; 2014

    12 & amp; #x2F 31 & amp; #x2F; 2014

    01/01/2014 and 31/12/2014.  I found that the only element relates to this suggests that this is a possible bug:

    SQL Bind Variables workshop - Date issues

    Any thoughts on how to address this issue, or is it really a bug?

    I run on Apex 4.2, 11g.

    Thank you!

    Hello

    I guess that these dates come from elements on the page to which the user can select a range of dates.

    These fields have a custom format mask?

    What seems to be the case for me, is that these fields have an explicit format mask (for example: DD/MM/YYYY) but the default database/session format mask is something different (e.g. DD-MON-YYYY).

    I suppose also that the issue in the SQL workshop isn't something related.

  • default values for VO bind variable

    Hi all

    I have a VO with bind variable year and month

    These variables have values as:


    year:

    cannot import

    DF = new SimpleDateFormat("yyyy")

    DF.format (ADF. CurrentDate)

    month:

    cannot import

    DF = new SimpleDateFormat ("MM")

    DF.format (ADF. CurrentDate)

    I have a table in my application this VO-based. I added these two variables as a counter entry number and a command button (ExecuteWithParams)

    The table is delivered with these variables dafult (2014 & 2). That's ok. Problem is that default values are not in the number of counters during the loading of the page.

    When I enter the new values (2014 & 1) and click the button, the new values to come and there is no problem...

    JDev version is 11.1.2.4

    Thank you...

    I find the solution as:

    In the pageDefinition file > binaries > ExecuteWithParams1_p_year > DefaultValue value as value: #{MyBean.year}

Maybe you are looking for

  • I get the msg for the services "of the unregistered class interface.

    Whenever I try to start the windows installer, I get the msg class not registered.  What should I do?  Please help this semi-novice

  • Install and run android on playbook Simulator app

    Hello I developed an Android application and convert .bar demand also sign this request as a guideline for the blackberry playbook and sings the success fully. but I'm trying to install this application on blackberry app playbook install perfect but

  • Unit 8 connection - can not see optional services

    Hello everyone - I'll try to find the "optional services" to activate proxy database in the connection unit 8 but when I enter the activation of the service, is not there (see attached screenshot).  Am I missing something or is my software screwed up

  • Photoshop CS6 will save the file as EPS or PDF.

    Hi guys. Forum first time poster here. It left me speechless.Computer: Intel (r) Core i7 with 16 GB of RAM and 600 GB free on my C: drive, you use Windows 10 and extended CS6.I have a complex shape file (made primarily of a pen tool) which is a solid

  • radial filter in the mobile app

    Hellois it possible to change the radial filter settings in the application?I can copy them to another photo, but it is possible to change them?Thank you