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

Tags: Database

Similar Questions

  • 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

  • How can I pass a value to a variable binding in a report query?

    I did a query of report to print a PDF report, with a dinamyc source query that has a connection variable, like this:

    SELECT EMPNO, EMPNAME, EMPDEPT

    FROM EMP

    WHERE EMPNO =: PARAMETER;

    I want to call the report print directly from a page, by using the url print showed by apex:

    f? p = & APP_ID.:0 : & SESSION. : PRINT_REPORT = MYREPORT

    How can I pass the value of the variable binding: PARAMETER using this URL?

    I don't think you can use the url parameter passes in a report query.

    the binding variable: PARAMETER must be a page element or an element of the application.

    use the "include session information and application" in the defination of report query to bind the value when the report is run

  • How to pass a list as a bind variable in SQL Developer?

    How can I pass a list as a bind variable in SQL Developer?

    The following query in SQL Developer so work I put ": prmRegionID = 2.

    SELECT COUNTRY_ID,
    COUNTRY_NAME
    OF HUMAN RESOURCES. COUNTRY
    WHERE IN REGION_ID (: prmRegionID);

    The problem is that I can't find how to set ": prmRegionID = 2, 3.

    I know that I can replace ": prmRegionID" by a proxy '& prmRegionID '. The above query will work well with"& prmRegionID = 2" and with "& prmRegionID = 2, 3". "

    But with this solution, I lost all the benefit of the use of bound variables (analysis hard against soft parse, possibility of SQL injection, etc.).

    I'm learning how to do this in SQL, as well as the use of UDT in this thread: How to move a list as a bind variable?

    But with this solution, I've lost nice SQL Developer user interface. In SQL developer, it is easy to test a query using the standard binding variable. When we start the application, a pop up asking for a value of the variable binding.

    With the UDT, the interface request always variable binding standard. You have an idea on how I can get a variable string binding (such as 1, 2, 10) in a set of NUMBER or VARCHAR2? This way I would be able to launch a standard query in SQL Developer to test my application.


    Can someone tell me what is the best approach to this?

    Thank you in advance,


    MB

    Hi Blais,

    Thank you for trying the SQL and PL/SQL instance before coming here - it was definitely the right approach, and you've got some very good suggestions there. Your needs for a invite only bind to the value in the clause list, I think I have a possible solution. I'll introduce you to a list of characters, so you'll have to tweak it for other types of data. First, add the following to your schema:

    create or replace
    TYPE bind_tab_typ AS TABLE OF VARCHAR2(4000);
    
    create or replace
    FUNCTION comma_to_table(iv_raw IN VARCHAR2)
    RETURN bind_tab_typ
    PIPELINED
    IS
       ltab_lname dbms_utility.lname_array;
       ln_len     BINARY_INTEGER;
    BEGIN
       dbms_utility.comma_to_table(list   => iv_raw
                                  ,tablen => ln_len
                                  ,tab    => ltab_lname);
       FOR i IN 1 .. ln_len LOOP
          PIPE ROW (ltab_lname(i));
       END LOOP;
    END;
    

    Now you can write a query, say for scott.dept, as follows, and have executed statement ask the value list in the clause as a single binding variable:

    select *
    from dept
    where dname in (
      select * from table( comma_to_table( :BNDS ))
    );
    

    When you are prompted, provide the list of values separated by a single comma without any extra spaces.

    I don't know if the Varchar2 (4000) really needs to be which is great. I use it because that's what dbms_utility.lname_array uses.

    Kind regards
    Gary
    SQL development team

  • literal and bind variables

    Hello

    What is the difference between literal and bind variables?
    What happens if I use
    literal variable has.
    variable b.bind

    who is suggested?

    Kind regards
    KKK

    There are two phases of any SQL performance.

    1. analysis (check Oracle this SQL syntax, also generates the implementation PLAN)
    2. execution (the real execution takes place)

    Below, SQL.

    Select * from emp where empno = 1234;

    I used literal in the SQL above.

    For each SQL type similar (average for empno modified value) oracle must analyze the SQL for each performance.

    Select * from emp where empno =: v_emp_no;

    I used the bind variable in the SQL above.

    In the oracle SQL above needs to analyze once, next time ehen this SQl will be executde with the value of the bound different variable, oracle will use the old execution PLAN and analysis will be not not happed. It will be a little fast.

    Also variable binding instead of literal use reduced use shared pool.

    HTH

    Best regards
    oratest

  • MB of Pass value to bind variable Groove

    Hello world. my version is 11.1.2.2

    I have a bean managed on the basis that contains two components of input (ex: name of user, pswd)
    I'm moving the input value to a query of VO that have variables bind with Groove. as adf.context.current...
    If it is possible, what is the expression to access the value of the bean components managed?

    THX

    Just follow this
    (1) for the vo, generate the VOImpl and when you create, select the variable bind method also
    (2) has the VOimpl who take a parameter, set the varialbe bind using the method and run the query method
    (3) expose this method as a customer interface
    (4) in the pagedefinition file, create an action method and select this method and have a binding method
    (5) of the managed bean, use the following code to execute the method

    OperationBinding operation = bindings.getOperationBinding("operation_name");
             operation.getParamsMap().put("parameter_name", parameterValue); /// this will be u r bind variable parameter
             operation.execute();
             if (operation.getResult() != null) {
                      Boolean result = (Boolean) operation.getResult(); // cast to the expected result type
            }
    
  • The use of bind variables in dynamic query created for Ref Cursor

    Hello

    I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
    The application is currently using literals instead of bind variables.

    code snippet of the above is
    strSql: = "select * from emp where 1 = 1 and ().

    loop cursor1
    If cond is true then
    strSql = strSql | "ename = ' |" Cursor1.ColumnName;
    end loop;

    Open cursor2 for strSql;

    How to use links in the example above.

    sb92075 wrote:

    user13019948 wrote:
    Hello

    Here is the code I have my trying to change literal-based link to the base.

    What do you mean by "based bind?

    who, what, how determines the values to be 'bound '?

    He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.

    If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.

    This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of

    AND t_names(i) = t_values(i)
    

    for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of

    select description from attribute where attribute_id = :b1 and name = :b2
    

    by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).

    declare
       k_sql_base        constant varchar2(500) := 'select description from attribute';
    
       t_names           constant varchar2_t := varchar2_t('attribute_id',  'name');
       t_values          constant varchar2_t := varchar2_t('1012',          'ISIN');
    
       l_sql             varchar2(500) := k_sql_base;
       l_rows_fetched    integer := 0;
       l_value           varchar2(4000);
    
       l_cursor_handle   integer;
    
    begin
       -- Construct the SQL statement with column names and bind variables e.g.
       -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2'
       for i in t_names.first .. t_names.last loop
          l_sql := l_sql ||
             case i
                when t_names.first then ' where ' else ' and '
             end ||
             t_names(i) || ' = :b' || i;
       end loop;
    
       dbms_output.put_line('SQL statment = ' || l_sql); 
    
       -- Parse the statement we built above (the remaining steps require a parsed cursor):
       l_cursor_handle := dbms_sql.open_cursor;
       dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native);
    
       -- Associate the 1st column of output with variable l_value - required for SELECT statements:
       -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string -
       -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different.
       -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.)
       dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000);
    
       -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE)
       for i in t_values.first .. t_values.last loop
          dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i));
          dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i));
       end loop;
    
       -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result):
       l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle);
    
       -- 'Returns value of the cursor element for a given position in a cursor'
       -- Copy the value of column 1 to variable l_value (has to match
       -- dbms_sql.column_value(l_cursor_handle, 1, l_value);
       dbms_sql.column_value(l_cursor_handle, 1, l_value);
    
       dbms_output.put_line('Result = ''' || l_value || '''');
    
       dbms_sql.close_cursor(l_cursor_handle);
    end;
    

    Hope that helps...

  • 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 )

  • 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

  • Convert SQL to take advantage of the Bind Variables

    Hi all

    Is it possible to convert the SQL below so I can enjoy variable Bind?  It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...

    ACCEPT script_name_like prompt 'ENTER SCRIPT NAME OR HIT ENTER TO GET ALL SCRIPT NAME OR PUT PART OF THE SCRIPT NAME : ' 
    WITH help_script AS
    ( SELECT 'top_seg_tab_obj_ash'                    AS Script_Name,
                        'top segment by tot wait time' AS Description,
                        '# of mins to go back'            AS INPUT
       FROM dual  
      UNION ALL SELECT 'v$_tab'                    AS Script_Name,
                        'shows list v$ views' AS Description,
                        'view name like'            AS INPUT
       FROM dual
      UNION ALL SELECT 'dba_tab'                    AS Script_Name,
                        'shows list dba views' AS Description,
                        'view name like'            AS INPUT
       FROM dual
      UNION ALL SELECT 'nls_params'                    AS Script_Name,
                        'shows list of current NLS setting for DB/INST/SESS' AS Description,
                        'no Input Needed'            AS INPUT )
    SELECT upper(script_name) AS "MY SCRIPT NAME",
           upper(description) AS description,
           upper(INPUT) AS INPUT
    FROM help_script
    WHERE script_name LIKE nvl('%&script_name_like%', script_name) ;
    

    Hello

    user13454469 wrote:

    Hi all

    Is it possible to convert the SQL below so I can enjoy variable Bind?  It's just my personal way of followed by the name of the script that I use on a daily basis... the file is passed to a point that its about 2K lines long, and whenever I run this specific file to get a script name, it creates a new SQL in the database pool shared... I tried to change this option to use bind variables , but it doesn't seem to work properly and I wanted what suggestion of the community...

    1. ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '
    2. WITH help_script AS
    3. (SELECT "top_seg_tab_obj_ash" AS Script_Name,
    4. "upper segment by tot queue time" AS Description,.
    5. "# of minutes to go back" AS INPUT
    6. OF the double
    7. UNION ALL SELECT ' v$ _tab "AS Script_Name,.
    8. "Show list views$ v ' AS Description,.
    9. 'show the name as' AS ENTRY
    10. OF the double
    11. UNION ALL SELECT 'dba_tab' AS Script_Name,
    12. "Show list views dba" AS Description,.
    13. 'show the name as' AS ENTRY
    14. OF the double
    15. UNION ALL SELECT 'nls_params' AS Script_Name,
    16. 'displays the list of current NLS parameter for DB/INST/SESS' AS Description,.
    17. ("No input is necessary" IN ENTRY)
    18. SELECT upper (script_name) AS "MY SCRIPT NAME",
    19. Upper (Description) as a description,
    20. Upper (Input) AS INPUT
    21. OF help_script
    22. WHERE script_name AS nvl (script_name ' % & script_name_like %',);)

    The WHERE clause (last line) of is the only place where you are using the proxy & script_name_like?  If so:

    -ACCEPT command is exactly the same as before

    ACCEPT script_name_like invites ' ENTER NAME or HIT ENTER to GET ALL THE SCRIPT NAME or PART OF THE SCRIPT the SCRIPT NAME: '

    VARIABLE script_name_like_b VARCHAR2 (30)

    EXEC: script_name_like_b: = '% & script_name_like;

    WITH the help _script AS

    ...

    WHERE script_name AS NVL (: script_name_like_b, script_name);

  • PLS-00049: bad bind variable 'NEW.col1' (col1 exists in the table)

    I use Oracle 12 c. And a bad bind variable error in this statement.

    create or replace

    check_tax_number relaxation

    INSERT BEFORE THE "C ##MYUSER". "customer" FOR EACH ROW

    BEGIN

    '0' IF new.taxpayer <>THEN

    : new.taxnumber: = "123456789";  -error here...

    END IF;

    END;

    I don't know which exists taxnumber customer in the table column.

    Here's desc 'C ##MYUSER '. "" customer ".

    Name of Type Null

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

    taxpayer NOT NULL NUMBER (1)

    taxnumber NOT NULL NVARCHAR2 (10)

    Other passes...

    Thanks for help.

    Based on the declaration of the customer table you posted columns are created in lowercase. Therefore, you must use the names of column between quotation marks:

    create or replace

    check_tax_number relaxation

    INSERT BEFORE THE "C ##MYUSER". "customer" FOR EACH ROW

    BEGIN

    IF : new. " taxpayer""" <> '0' THEN

    : new. " " "taxnumber""": = "123456789";  -error here...

    END IF;

    END;

    SY.

  • Procedure of the ODI - Bind Variables in the conditional statements

    In an ODI procedure, is it possible to add a conditional statement around bind variable?  For example, if I use OdiOutFile as the command on the target and Oracle as the command on the Source, I can use bind variables to fill the data in this table (we are in fact using OdiInvokeWebService and passing a XML structure very complex, but it's easier for testing):

    OdiOutFile-FILE = C: / TEST. TXT

    < person >

    < first > #FIRSTNAME < / first >

    < Middle > #MIDDLENAME < / Middle >

    < last > #LASTNAME < / last >

    < / person >

    It is a way to add a conditional statement using one of these bind variables?  For example, if I wanted to test #MIDDLENAME null and null value, produced this portion of XML, such as:

    OdiOutFile-FILE = C: / TEST. TXT

    < person >

    < first > #FIRSTNAME < / first >

    < % if (#MIDDLENAME! = null) {% >}

    < Middle > #MIDDLENAME < / Middle >

    < %} % >

    < last > #LASTNAME < / last >

    < / person >

    This type of scriptlet syntax seems to work fine, as long as the binding variable is not in the mix (if I put "true is true" or "true == false" in the case, it shows or does not show this line in the XML file, as expected).  I use ODI 11.1.1.7.0

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

    Post edited by: KevinPratt

    Thanks for the reply!  As suggested, in what follows, I changed the command and it works as you want

    OdiOutFile-FILE = C: / TEST. TXT-APPEND

    < person >

    < first > #FIRSTNAME < / first >

    < @ if (!) (("#MIDDLENAME".equals(""))) {@ >}

    < Middle > #MIDDLENAME < / Middle >

    {< @} @ >

    < last > #LASTNAME < / last >

    < / person >

    Using the syntax <@ ...="" @="">serve your purpose. Also, I think you might want to include the variable binding in the quotation to avoid syntax errors.

Maybe you are looking for

  • Security updates will not download.

    According to me, that I'm missing some dll files. I had a few malware - 'Searchqu' a few months ago and now my computer starts acting... The wil files do not download updates of security.

  • Text size in Firefox, IE, Outlook Express

    Newly built pc with newly installed XP Pro 2002 SP3. In Firefox 3.6, I put some tools/options/content = Times New Roman 24; in advanced size 24; Allow pages select etc. is not enabled. Some web sites display the text of agreement, while some websites

  • Windows security KB2660649 update failed to download

    The Windows Update Securty KB2660649, was download and stop and showed the error.  Error 8E5E0147. My pc HP Pavillion RX881AA-ABA, Windows Vista Home Premium (32 bit). Office {information}

  • Cannot save the keys

    Hello! I had the keys and successfully saved. But something went wrong and I did not create debugging token: could not decrypt key file error. So I got new keys. But unable to save: Error: Already registered with RDK Error: Already registered with CO

  • Rename the table sys

    Hi all11.2.0.1How to rename scott.emp in as SYS scott.emp2?SQL > connect / as sysdbaConnected.SQL > rename scott.emp in scott.emp2;*ERROR on line 1:ORA-01765: specifying the name of the owner of the table is not allowedThank you all,pK