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

Tags: Database

Similar Questions

  • Bind Variables in SPARQL queries

    Hello

    I am interested in bind variable and use between requests, but if I understand the concept that underlies the example given in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#autoId15) I'm not able to grasp how exactly to the results of a query_1 for a ? x variable to another query_2query.

    Would it not possible to provide a more detailed explanation and a simple code working on how to do it using Jena Adapater.

    Thank you.

    Sorry for the late reply. Was tied up with a date limit.

    Here is a complete example.

    (1) assumes a model with the following triplets

    % test/forum2550843.nt cat

    .

    .

      .

    .

    .

    (2) run the following query to obtain the values of bind and internal ID resources

    % Cat./tests/forum2550843.sparql1

    PREFIX oext: http://oracle.com/semtech/jena-adaptor/ext/function#>

    Select? x (oext:build - uri-for-id(?x) as? xid)

    where {? y ? x}

    Here is a possible answer to the query above.

    soln (? xid = <> 6354524810780932050>) (? x = )

    (3) to say we want to push the values to bind to? x from the above query in

    "SELECT? topic? "x WHERE {? subject? x}"

    We can build and run the following query:

    % Cat./tests/forum2550843.sparql2

    PREFIX ORACLE_SEM_FS_NS: http://oracle.com/semtech#no_fall_back>

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

    PREFIX ORACLE_SEM_UEPJ_NS: http://oracle.com/semtech#x $RDFVID>

    PREFIX ORACLE_SEM_UEBV_NS: http://oracle.com/semtech#6354524810780932050>

    SELECT? topic? x

    WHERE {}

    ? topic ? x

    }

    Here are the answers:

    soln (? x = ) (? subject = )

    soln (? x = ) (? subject = )

    It will be useful,

    Zhe Wu

  • Problem using bind variables in shared components report queries

    Greetings,

    I use APEX 4.0.1.00.03 and BI Publisher 10.1.3.4.1.

    In the APEX, I try to create a report query that uses bind variables in the where clause. I have a page that contains a button and a text element (P1_ID). The button is used to call the report. I went the shared components and created a new report query. Here is the text of the code.
    select violation_date
    , violation_type
    , nvl(:P1_ID,'zzz')
    from edd_procard_violations
    where upper(card_holder_id) = upper(:P1_ID)
    I also have Session State to enabled and have added the P1_ID in the area of 'State of Session' under the query.

    When I change the query, and click on the 'Set Bind Variables' button, I get a field where I can enter a value for: P1_ID I enter a value that should return lines, but when I click on the button "Test query", I get no rows returned. If I comment on where clause and test the query, even once, I get all rows in the table. You'll notice in my query I have included nvl(:P1_ID,'zzz'). When I run the query, without where clause, the returned value is always "zzz" indicating that: P1_ID is null.

    No idea what I am doing wrong?

    Thank you very much.
    Larry

    Hello Larry,.

    Looks like the wizard to create a report query in the shared components has a bug related to bind variables. I was able to reproduce your problem. Just create the query using the link variable, check the box to include session state, add the item and create the query. When you use the report query to download the report, where the your clause will work fine.

    Thank you
    Machaan

  • 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

  • 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

  • Refcursor bind variables

    Hi all

    I have a variable refcursor, to which I will assign running queries.

    All are defined (union) queries, with 5 or 6 selects the union, each select returns the same variable where clause. Value of the variable will be known at run time.

    For example: (just an example)

    {code}

    Start

    v_sql: = ' select col1, col2

    of the Department

    where dept_no =: 1

    Union

    Select col1, col2

    of eur_dept

    where dept_no =: 1

    Union

    Select col1, col2

    of us_dept

    where dept_no =: 1 ';

    Open the v_ref_cur for v_sql using 20, 20, 20;

    -rest of the logic

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

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

    end;

    {code}

    Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.

    Thank you!

    DS says:

    Question is how to avoid the bind variable value repeat (in the open statement). Is there a way I can mention value 20 only once when the cursor is opened.

    Yes - can be done using a dynamic anonymous block to create the refcursor (containing the SQL text), as oppose to the creation of the refcursor directly from the SQL text.

    Not an approach I consider myself - unless there is absolutely no better way to address this particular issue.

    SQL > var refcursor c.

    SQL >

    SQL > declare

    News 2 sys_refcursor;

    3. start

    4 immediate execution

    5 ' declare

    6 varchar2 (4000) var1: =: 1;  -/ / simple definition var - used several times

    7. start

    open 8: news for

    9 select * from emp where mgr = var1

    10 the union all the

    11. Select * from emp where empno = var1;

    12 end; »

    13 using 7698-past the variable once

    14 in the news; -getting refcursor as answer

    15

    16: c: = cur;

    end 17;

    18.

    PL/SQL procedure successfully completed.

    SQL >

    SQL > print c

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR

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

    7499 ALLEN SALESMAN 7698 1981/02/20 00:00:00 1600 300 30

    7521 WARD SALESMAN 7698 1981/02/22 00:00:00 1250 500 30

    7654 MARTIN SALESMAN 7698 1981/09/28 00:00:00 1250 1400 30

    7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30

    7900 JAMES CLERK 7698 1981/12/03 00:00:00 950 30

    7698 BLAKE MANAGER 7839 1981/05/01 00:00:00 2850 30

    6 selected lines.

    SQL >

  • SQL Bind Variables workshop - Date issues

    I use SQL Workshop to run through some queries. I'm having a problem with Bind Variables that contain dates. I enter the following date:

    12/12/2013

    but it is converted to:

    12 & amp; #x2F 12 & amp; #x2F; 2013

    I'm doing something wrong?

    Thank you
    Glen

    It looks like a bug. It should not escape what either.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Apress.com/9781430235125
    http://Apex.Oracle.com/pls/Apex/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

  • How to find the query select bind variables

    How to extract the variable name to bind to AS suite of sql queries
    ' SELECT NAME IN: NAME OF THE DOUBLE '
    or
    "SELECT * FROM WHERE DOUBLE (: NAME = NAME)".
    or
    "SELECT * FROM WHERE DOUBLE: NAME IS NULL'."
    or
    "SELECT * FROM WHERE DOUBLE: NAME | NAME = LAST_NAME'
    or
    ' SELECT * FROM DUAL WHERE: a = 10'
    or
    "SELECT * from where DOUBLE: A > = 10'.
    or
    "SELECT * from where DOUBLE: A < = 10 '.

    Give a solution using SUBSTR, REGEXP_SUBSTR, please answer quickly
    best answer will be marked correct/good...

    Search: and then search for the following word breaker then have the substr for them: and the separator.
    You can build an own function to find the same.

  • Performance tests: bind variables

    When you write a SQL for the application, I want to do some performance testing of SQL before providing to JAVA developers. I understand that I need to test using bind variables, can someone guide me how do? What are the best tools out there to achieve? Please provide some guidance. Thank you!

    Rinne says:
    I read more about bind variable and I can test the use of bind variables. I understand that testing SQL using bind variables is a closer representation of the real world. Even when queries have large tables, the performance would be similar if I run the query using literals twice (to avoid hard analysis) compared to tests with bind variables? I am trying to understand more thoroughly the need for tests with bind variables. Why we take more time than the other? Thank you!

    The main thing is that the opimizer will / can do if bind variables different optimization techniques are used or not.
    There are two contradictory effects its regarding the binding settings.

    Effect 1: Reuse of cursor
    If the same is done again and again and again. Maybe different sessions. Then using binding settings is essential. Why? Because the same cursor can be reused, which saves a lot of time for analysis. This occurs mainly in OLTP systems. The idea behind this is that to do the same action, just for a different ID (ID in order for example) will result in an identical implementation plan.

    The result: Faster analysis time and less consumption of memory, because the same cursor can be resused between different sessions.

    Effect 2: Correct assumptions

    According to a filter expression, some using the value of the OBC will make an assumption based on statistical data the number of rows is returned because of this expression and the value.
    Speculation between a literal value and a bound value may be different. In many cases exist technical opimization (bind peeking etc.) to the same literal conjecture binded proposal.

    But there are exceptions, for example a condition such as the following will result in different estimates

    column between 10 and 20
    
    column between :P1 and :P2
    

    There are as well other effects.

    Result: The CBO can make assumptions better if literals. But most of the cases the proposal is identical.

    Conclusion: Literal values are useful if you do large queries where the output size depends strongly on the parameters provided, and where you run that very few of these (OLAP) queries.
    Binding settings are usfull when the same execution (OLTP) need a grand plan number of queries.

  • The use of bind variables (in &amp; out) with sql dynamic

    I have a table that contains code snippets to make postings on a set of pl/sql database. what the code does is basically receives an ID and returns a number of errors found.
    To run the code, I use dynamic sql with two bind variables.

    When codes consists of a simpel query, it works like a charm, for example with this code:
    BEGIN
       SELECT COUNT (1)
       INTO :1
       FROM articles atl
       WHERE ATL.CSE_ID = :2 AND cgp_id IS NULL;
    END;
    However when I get to post more complexes that must perform calculations or run several queries I run into trouble.
    I have boiled down the problem into that:
    DECLARE
       counter   NUMBER;
       my_id     NUMBER := 61;
    BEGIN
       EXECUTE IMMEDIATE ('
          declare 
             some_var number;
          begin
          
          select 1 into some_var from dual
          where :2 = 61; 
          
          :1 := :2;
          end;
    ')
          USING OUT counter, IN my_id;
    
       DBMS_OUTPUT.put_line (counter || '-' || my_id);
    END;
    This code is not really make sense, but it's just to show you what is the problem. When I run this code, I get the error
    ORA-6537 ON bind variable linked to a position IN

    The error doesn't seem wise,: 2 is the only one IN bind variable and it is only used in a where clause clause.
    As soon as I remove this where clause, the code works again (giving me 61-61, in case you want to know).

    Any idea what goes wrong? I just use bind variables in a way that you're not supposed to use it?

    I'm using Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit

    Correction. With immediate execution , the binding is in position, but binds do not need to be repeated. My statement above is incorrect...

    You must link only once - but bind by position. And the connection must correspond to the use of the variable binding.

    If the connection never variable assigns a value in the code, link by in.

    If the binding variable assigns a value in the code, link as OUTPUT.

    If the binding variable assigns a value and is used a variable in another statement in the code, link as IN OUT.

    For example

    SQL> create or replace procedure FooProc is
      2          cnt     number;
      3          id      number := 61;
      4  begin
      5          execute immediate
      6  'declare
      7          n       number;
      8  begin
      9          select
     10                  1 into n
     11          from dual
     12          where :var1 = 61;       --// var1 is used as IN
     13
     14          :var2 := n * :var1;     --// var2 is used as OUT and var1 as IN
     15          :var2 := -1 * :var2;    --// var2 is used as OUT and IN
     16  end;
     17  '
     18          using
     19                  in out id, in out cnt;  --// must reflect usage above
     20
     21          DBMS_OUTPUT.put_line ( 'cnt='||cnt || ' id=' || id);
     22  end;
     23  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc
    cnt=-61 id=61
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Create the collection of query with bind variable

    Apex 4.0.2

    By Joel Re: Collection with variable binding the apex_collection.create_collection_from_query_b supports queries containing references to the bind variables (: P1_X) but I don't know how to use this feature, the documentation is not an example, just the API signature for the overloaded version has changed.

    If the query contains 2 bind session state variable references (: P1_X and: P1_Y), can someone please show an example of what to spend for the parameters p_names and p_values to the API?

    Thank you
    procedure create_collection_from_query_b(
        --
        -- Create a named collection from the supplied query using bulk operations.  The query will
        -- be parsed as the application owner.  If a collection exists with the same name for the current
        -- user in the same session for the current Flow ID, an application error will be raised.
        --
        -- This procedure uses bulk dynamic SQL to perform the fetch and insert operations into the named
        -- collection.  Two limitations are imposed by this procedure:
        --
        --   1) The MD5 checksum for the member data will not be computed
        --   2) No column value in query p_query can exceed 2,000 bytes
        --
        --
        -- Arguments:
        --     p_collection_name   =  Name of collection.  Maximum length can be
        --                            255 bytes.  Note that collection_names are case-insensitive,
        --                            as the collection name will be converted to upper case
        --     p_query             =  Query to be executed which will populate the members of the
        --                            collection.  If p_query is numeric, it is assumed to be
        --                            a DBMS_SQL cursor.
        -- example(s):
        --     l_query := 'select make, model, caliber from firearms';
        --     apex_collection.create_collection_from_query_b( p_collection_name => 'Firearm', p_query => l_query );
        --
        p_collection_name in varchar2,
        p_query           in varchar2,
        p_names           in wwv_flow_global.vc_arr2,
        p_values          in wwv_flow_global.vc_arr2,
        p_max_row_count   in number default null)
        ;

    HELEN wrote:
    Apex 4.0.2

    By Joel Re: Collection with variable binding the apex_collection.create_collection_from_query_b supports queries containing references to the bind variables (: P1_X) but I don't know how to use this feature, the documentation is not an example, just the API signature for the overloaded version has changed.

    If the query contains 2 bind session state variable references (: P1_X and: P1_Y), can someone please show an example of what to spend for the parameters p_names and p_values to the API?

    Not tried, but guess something like

    apex_collection.create_collection_from_query_b(
        p_collection_name => 'foobar'
      , p_query => 'select f.foo_id, b.bar_id, b.baz from foo f, bar b where f.foo_id = b.foo_id and f.x = to_number(:p1_x) and b.y = :p1_y'
      , p_names => apex_util.string_to_table('p1_x:p1_y')
      , p_values => apex_util.string_to_table(v('p1_x') || ':' || v('p1_y')))
    
  • The use of bind variables in the application process

    Bind variables refer to elements of session state supported in queries in an application request process?

    All the examples I see show how to pass client side values using the $v () function and the htmldb_get object addParam method and refer to them using the wwv_flow.g_xNN variables, but already available in session state values, I should be able to use them directly in the process, right?

    Thank you

    Yes, they are supported.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

  • Can OBIEE use Bind Variables?

    I doubt that it would be used for warehouse queries, but I'm the question arises. Has anyone used in OBIEE?

    [Here is a brief summary about them. | http://www.akadia.com/services/ora_bind_variables.html]

    I checked with the support of Oracle and it's official - OBIEE does not support the bind variable.

  • Bind variables improve query performance?

    Hello

    Bind variables improve the performance of the program or a SQL query.

    Select empno, ename, sal from emp where empno =: eno;

    Select sal in: emp WNV;

    According to these queries I request performance of the bind variable to learn more from you.



    Kind regards
    Vincent.

    Published by: Venkata2 on September 16, 2008 18:40

    any variable inside a stored procedure is one of liaison.

    the use of bind variables can help you avoid analysis difficult. which leads to the improvement of the performance.

    Thank you
    Knani.

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

Maybe you are looking for

  • How can I sync my address book in ThunderBird with Gmail?

    Once I have all the details in my ThunderBird addressbook, can they be in sync with gmail?If so, how?BTW. My gmail account is connected to Thunderbird.

  • How to change the cup of cups on a recipe by the numbers

    I create a recipe in number and I wish it was a plural version of Cup.  I do not know how to change the existing resize options.  So instead of read 6 cups he would say 6 cups.

  • alligaterdanger

    I can't update my iphone via itunes applications. They do not display anything and it doesn't show any available updates. Please help me... **************** < email published by host >

  • Arrested Guide download in Media Center (XP)

    My listings guide stopped to update almost a week ago. I tried to configure my guide new ads as well as Media Center.

  • Problem with updates! Microsoft files won't open!

    My HP just installed automatic updates and then I couldn't access my Microsoft Office files! I went back to the point files and its fine, but I'm afraid to leave my computer to install updates again! What is going on! What should I do? (FYI - I have