Bind variables in jena WLS SPARQL Queries

Dear all,
We have read about the possibilities of the jena support for bind variables in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#RDFRM248). In the following topic of jun 14 2014 (Bind Variables in SPARQL Queries) the problem was already addressed. However we are facing some other problems.
We are using:
* WLS 12.1.3.0.0
* jena adapter 2.11.1.
* Joseki 3.4.4.
* ARQ 2.9.2.
We try to run the following query on the joseki end-point.
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,ALLOW_DUP=T,ODS=6,s2s>
PREFIX ORACLE_SEM_HT_NS: <http://oracle.com/semtech#monitor>
PREFIX ORACLE_SEM_UEAP_NS: <http://oracle.com/semtech#f$RDFVID%20in(?)>
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 { ?p vcard:N ?vn .
              ?vn vcard:Family ?f .
               ?p foaf:title "Sen." .}
The result we get back is however not using the bind variable. It returns the whole list without UEAP/UEPJ/UEBV.
Is there something I missed in the documentation or do I need to set some variables for the use of bind variables?
Kind regards,
Max

Dear Zhe,
The solution provided works! However setting this property was not straight forward for me (but this is more related to WLS).
Setting this JVM property in the arguments of the weblogic server (Server Start) does not work. I've looked through the files for any sign of the property but did not find any. Manually adding this line in setDomainEnv.sh
(adding the variable JAVA_PROFILE = "-Doracle.spatial.rdf.client.jena.allowAP=true") does work though.
Kind regards,
Max

Similar Messages

  • Passing literal as bind variable in jena

    Dear all,
    We are able to use bind variables using the RDFVID id. However if we want to check for a literal using the jena/joseki adapter we are not able to perform the same action. In our case the literal is of type string.
    We are using:
    * WLS 12.1.0.3.
    * Jena adapter 2.11.1.
    * Joseki 3.4.4.
    * ARQ 2.9.2.
    We try to run the following query on the joseki end-point.
    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%20in(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 { ?p vcard:N ?vn .
       ?vn vcard:Family ?f .
        ?p foaf:title "Sen." .}
    The result set is empty. Replacing the line 'PREFIX ORACLE_SEM_UEBV_NS: <http://oracle.com/semtech#"Lee">' by any variant is either given an error or the empty set. (Some variants are (&quot;Lee&quot; , Lee, "Lee", &#39;Lee&#39; )
    When we use the generated SQL from jena/joseki, we are able to get the right result if we run the same query in SQLDeveloper. The bind variable we have to use is "Lee" (the bind variable has the quotations included). This will give the correct result set back.
    Kind regards,
    Max

    Hi Max,
    In the UEBV field, you need to put in URL encoded String of "Lee"
    Please try the following and see if it helps.
    %22Lee%22
    Thanks,
    Zhe Wu

  • Bind Variable reuse in GROUP BY queries

    We have several queries that are rather large (in are opinion, that is) and they each have 10 '?' place holders for binding JDBC parameters. These queries also use bind variables in the WHERE and GROUP BY clauses. Eventhough there are 10 bind variable place holders ('?'), there are only 3 distinct values needed.
    So...in TOAD or SQL*Plus, we run the queries and "reuse" the same three bind variables and the query works fine. If we use 10 different bind variables, filled with the 3 values, we get a an error, "not a GROUP BY expression."
    We would like to make these calls as JDBC PreparedStatements and bind the parameters at run time, so that we could take advantage of the statement cache and increase performance. But...since JDBC parameter binding seems to be positional, we seem to be getting 10 different bind variables at runtime in the PreparedStatement call. Is there a way to "reuse" the bind variables that JDBC is binding at runtime?
    Regards,

    Yep...that is what we are doing. We have a work around that is to manually replace the ? with string data and then pass the query in complete. It will work fine for us. I was just checking the alternatives. The query is large, but the offending code is:
    ...( select distinct T3.ptcpt_cd,trunc(new_time(T1.start_dt_gmt, 'GMT', ?)) trade_date,
    sum(decode(T1.sttl_item_num, 10, T1.sttl_item_qnty, 0)) DA_CHARGE_MW,
    sum(decode(T1.sttl_item_num, 10, T1.sttl_item_amt, 0)) DA_CHARGE_AMT,
    sum(decode(T1.sttl_item_num, 30, T1.sttl_item_qnty, 0)) BAL_CHARGE_MW,
    sum(decode(T1.sttl_item_num, 30, T1.sttl_item_amt, 0)) BAL_CHARGE_AMT,
    sum(decode(T1.sttl_item_num, 20, T1.sttl_item_qnty, 0)) DA_CREDIT_MW,
    sum(decode(T1.sttl_item_num, 20, T1.sttl_item_amt, 0)) DA_CREDIT_AMT,
    sum(decode(T1.sttl_item_num, 40, T1.sttl_item_qnty, 0)) BAL_CREDIT_MW,
    sum(decode(T1.sttl_item_num, 40, T1.sttl_item_amt, 0)) BAL_CREDIT_AMT,
    T3.source_cd Source
    from nm_sttl_item_dtl T1, nm_settlement T2, nm_sttl_statement T3
    where trunc(new_time(T1.start_dt_gmt, 'GMT', ?)) between to_date(?,'mm/dd/rrrr') and to_date(?,'mm/dd/rrrr')
    and sttl_item_num in (10, 20, 30, 40)
    and (sttl_item_qnty <> 0 and sttl_item_amt <> 0)
    and T1.sttl_id = T2.sttl_id
    and T2.statement_id = T3.statement_id
    and T3.ptcpt_cd = 'FAC'
    and T3.source_cd = AREA'
    group by T3.ptcpt_cd,trunc(new_time(T1.start_dt_gmt, 'GMT', ?)), T3.source_cd)...

  • Bind Variables in SPARQL Queries

    Hi,
    I am interested in bind variables and their use between queries, however while I see the concept behind the example given in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25609/sem_jena.htm#autoId15) I am not able to grasp how to exactly pass the results of a query_1 for an ?x variable to another query query_2.
    Would it be possible to offer a more detailed explanation and a working simple code about how to do this using Jena Adapater.
    Thank you.

    Hi,
    I am using the Java API to run SPARQL update queries, this is an example of what I am trying to achieve :
    public static void runTestUpdateBinding() throws SQLException {
        String[] modelNames = new String[] { };
        String[] rulebases = new String[] { };
        OracleDataSource ods = new OracleDataSource();
        ods.setURL("ORACLE CONNECTION STRING");
        OracleConnection oc = (OracleConnection)ods.getConnection();
        Oracle oracle = new Oracle(oc);
        Attachment attachment =
            Attachment.createInstance(modelNames, rulebases, InferenceMaintenanceMode.NO_UPDATE, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP);
        GraphOracleSem graph = new GraphOracleSem(oracle, "in_oracle", attachment, true);
        ModelOracleSem model = new ModelOracleSem(graph);
        //Insert few triples
        String updateQuery = "INSERT DATA {                                        " +
                             "  <http://sub/a>  <http://pred/a>  <http://obj/a> .\n" +
                             "  <http://sub/b>  <http://pred/b>  <http://obj/b> .\n" +
                             "  <http://sub/c>  <http://pred/c>  <http://obj/c>    " +
        UpdateAction.parseExecute(updateQuery, model);
        //Run the update query
        updateQuery = "PREFIX    ORACLE_SEM_UEAP_NS:    <http://oracle.com/semtech#s$RDFVID%20IN(ORACLE_ORARDF_RES2VID(?),ORACLE_ORARDF_RES2VID(?))> \n" +
                      "PREFIX    ORACLE_SEM_UEPJ_NS:    <http://oracle.com/semtech#s$RDFVID> \n" +
                      "PREFIX    ORACLE_SEM_UEBV_NS:    <http://oracle.com/semtech#http%3A%2F%2Fsub%2Fa,http%3A%2F%2Fsub%2Fc> \n" +
                      "INSERT { <http://sub/UPDATED_SUBJECT>    ?p    ?o } \n" +
                      "WHERE  { ?s    ?p    ?o }";
        UpdateAction.parseExecute(updateQuery, model);
        model.close();
    Basically, I am expecting only "<http://sub/a>  <http://pred/a>  <http://obj/a>" and "<http://sub/c>  <http://pred/c>  <http://obj/c>" to match, however, "<http://sub/b>  <http://pred/b>  <http://obj/b>" also matches as you can see from the following results
    | s                            | p               | o              |
    ===================================================================
    | <http://sub/c>               | <http://pred/c> | <http://obj/c> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/c> | <http://obj/c> |
    | <http://sub/b>               | <http://pred/b> | <http://obj/b> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/b> | <http://obj/b> |
    | <http://sub/a>               | <http://pred/a> | <http://obj/a> |
    | <http://sub/UPDATED_SUBJECT> | <http://pred/a> | <http://obj/a> |
    Also, in the underlying generated SQL, there is no restriction on s$RDFVID as in SELECT queries (i.e: ...where (s$RDFVID IN(ORACLE_ORARDF_RES2VID(?),ORACLE_ORARDF_RES2VID(?))) )

  • How to Dene a Data Link Between Queries: Bind Variables

    This is an interesting topic and I cannot get it to work using Bind Variables.
    I have 2 queries: Q1 and Q2. Q2 needs c_id, account_code and account_type from Q1.
    Whe I run the data template below, I get only the data for Q1.
    Now people may argue that there is no data in Q2 for the relevant clause. So if I even remove the where clause in Q2 I still get no joy i.e Data appears for Q1 but not for Q2
    <dataTemplate name="FLCMR519_DATA_SET" description="Termination Quote Report">
         <parameters>
              <parameter name="cid" dataType="number" defaultValue="1"/>
              <parameter name="p_cln_id" dataType="number" defaultValue="62412"/>
         </parameters>
         <dataQuery>
              <sqlStatement name="Q1">
                   <![CDATA[SELECT qm.qmd_id,
    qm.contract_period,
    qm.quo_quo_id||'/'||qm.quote_no||'/'||qm.revision_no reference_no,
    qm.contract_distance,
    qm.mdl_mdl_id,
    q.qpr_qpr_id,
    q.quo_id,
    q.drv_drv_id,
    qm.revision_user username,
    pb.first_name||' '||pb.last_name op_name,
    pb.telephone_no,
    pb.facsimile_no,
    pb.email,
    q.c_id c_id,
    q.account_type account_type,
    q.account_code account_code,
    m.model_desc,
    ph.payment_description payment_head_desc,
    cl.fms_fms_id,
    cl.start_date,
    cl.end_date,
    cl.actual_end_date,
    cl.con_con_id,
    cl.cln_id,
    cl.term_qmd_id term_qmd_id,
    qm2.contract_period term_period,
    qm2.contract_distance term_distance
    FROM quotations q,
               quotation_models qm,
               contract_lines cl,
               personnel_base pb,
               models m,
               model_types mt,
               payment_headers ph,
               quotation_models qm2
    WHERE q.quo_id = qm.quo_quo_id
           AND cl.cln_id = :p_cln_id
           AND qm.qmd_id = cl.qmd_qmd_id
           AND qm2.revision_user = pb.employee_no (+)
           AND qm.mdl_mdl_id = m.mdl_id
           AND m.mtp_mtp_id = mt.mtp_id
           AND qm.payment_id = ph.payment_header_id
           AND qm2.qmd_id (+) = cl.term_qmd_id
    ]]>
              </sqlStatement>
              <sqlStatement name="Q2">
                   <![CDATA[SELECT ea.c_id,                  ea.account_type,ea.account_code,ea.account_name
    FROM external_accounts ea
                 WHERE ea.c_id = :c_id
                   AND ea.account_type = :account_type
                   AND ea.account_code = :account_code
    ]]>
              </sqlStatement>
         </dataQuery>
    </dataTemplate>

    Defining dataStructure section is mandatory for multiple queries.

  • Bind Variables

    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    I asked the following questions:
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    The answer are listed below.
    I tried using ODP bind variables technique using fixed array size and bind variables technique in ODP (the redundant vars were fulfilled with dummy values) . I used trace and tkprof (with SYS=NO) opposite oracle 9.2.0.5 and pare was equal to parse an fetch meaning : no reuse of execution plans.
    Do you have any IDEA????
    Best Regards
    David Yitzhak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: Alex Keh [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1504;&#1497; 10 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 23:50
    To: Ischack David; [email protected]
    Subject: Re: Securing a .NET Application on the Oracle Database
    David,
    In your example ("select col1,col2 ..coln from table where x in (value1,value2 ….)"), x is the name of a column, which does not need to have a bind variable. You can just put in a .NET variable representing the string value of the column name and concatenate the SQL statement together.
    We are planning to supprt objects and VARRAYs around January/February. From these, you can build your own Spatial data types. Today, most .NET Spatial users employ XML when using their Spatial data in .NET.
    Alex
    ----- Original Message -----
    From: Ischack David
    To: [email protected]
    Sent: Sunday, October 09, 2005 2:27 PM
    Subject: Securing a .NET Application on the Oracle Database
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    Best Regards
    David Itshak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: John Cook [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1500;&#1497;&#1513;&#1497; 11 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 4:15
    To: Ischack David
    Subject: Re: Some questions about bind variables , objects , Oracle spatialand ODP
    The situation you have described with multiple bind values is one I have considered. It's a problem. I think I can code a generic implementation, but doing so would take time away from activities that I get paid for.
    I haven't worked with Oracle Spatial.
    We'll have more articles on ODP.NET in the months ahead. I'm glad you liked Mark's article.
    ----- Original Message -----
    From: "Ischack David"
    To: [email protected]
    Subject: Some questions about bind variables , objects , Oracle spatial and ODP
    Date: Sun, 9 Oct 2005 23:27:24 +0200
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi

    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    I asked the following questions:
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    The answer are listed below.
    I tried using ODP bind variables technique using fixed array size and bind variables technique in ODP (the redundant vars were fulfilled with dummy values) . I used trace and tkprof (with SYS=NO) opposite oracle 9.2.0.5 and pare was equal to parse an fetch meaning : no reuse of execution plans.
    Do you have any IDEA????
    Best Regards
    David Yitzhak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: Alex Keh [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1504;&#1497; 10 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 23:50
    To: Ischack David; [email protected]
    Subject: Re: Securing a .NET Application on the Oracle Database
    David,
    In your example ("select col1,col2 ..coln from table where x in (value1,value2 ….)"), x is the name of a column, which does not need to have a bind variable. You can just put in a .NET variable representing the string value of the column name and concatenate the SQL statement together.
    We are planning to supprt objects and VARRAYs around January/February. From these, you can build your own Spatial data types. Today, most .NET Spatial users employ XML when using their Spatial data in .NET.
    Alex
    ----- Original Message -----
    From: Ischack David
    To: [email protected]
    Sent: Sunday, October 09, 2005 2:27 PM
    Subject: Securing a .NET Application on the Oracle Database
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi
    I have read happily the article The Values That Bind By Mark A. Williams (Oracle Magazine September/October 2005 ). Immediately I rushed to implement the article on over developers . The problem is that we have a SQL query using the in operators . For example : select col1,col2 ..coln from table where x in (value1,value2 ….).
    I such a case how can you \use the bind variables technique , which fit the queries in which each variable can have one value (e.g. select country_name
    from hr.countries
    where country_id = :country_id)
    ODP support Oracle spatial or at list using objects??
    Will ODP support oracle spetial???
    Best Regards
    David Itshak
    BSC (Information System), MBA
    .Net developer and Oracle and SQL Server Applicative /Infrastructure DBA
    From: John Cook [[email protected]]
    Sent: &#1497;&#1493;&#1501; &#1513;&#1500;&#1497;&#1513;&#1497; 11 &#1488;&#1493;&#1511;&#1496;&#1493;&#1489;&#1512; 2005 4:15
    To: Ischack David
    Subject: Re: Some questions about bind variables , objects , Oracle spatialand ODP
    The situation you have described with multiple bind values is one I have considered. It's a problem. I think I can code a generic implementation, but doing so would take time away from activities that I get paid for.
    I haven't worked with Oracle Spatial.
    We'll have more articles on ODP.NET in the months ahead. I'm glad you liked Mark's article.
    ----- Original Message -----
    From: "Ischack David"
    To: [email protected]
    Subject: Some questions about bind variables , objects , Oracle spatial and ODP
    Date: Sun, 9 Oct 2005 23:27:24 +0200
    Some questions about bind variables , objects , Oracle spatial and ODP
    Hi

  • Can't create multiple dependent LOVs from the same bind variable

    Hi all,
    I'm having difficulty creating multiple dependent LOVs from queries based on the same bind variable in my JSF application (JDev 10.1.3.1). Basically I have a static LOV in a af:selectOneChoice component from which users select a value which then becomes the bind variable value for two separate queries that generate two different dependent LOV. Having developed the code along the lines of Steve Muench 's blog (http://radio.weblogs.com/0118231/2006/04/03.html#a685), the first dependent LOV works really well. The first dynamic LOV gets refreshed whenever the list from the static LOV changes, and I can execute other queries based on the values selected.
    The problem arises when I want to create the second dynamic/dependent LOV that has the same bind variable based on the same selected value from the static LOV. Here I would also like the functionality whereby the second dynamic LOV is also refreshed after the selected value in the static LOV changes. Thinking that all I had to do was replicate the methodology used in creating the first dependent LOV, I created the second iterator, invokeAction and other binding components in the PageDef. The executable section now looks like the following:
    <iterator id="SelectStaticQueryViewObjIterator"
                  Binds="SelectStaticQueryViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>
    <invokeAction id="refreshDynamicQuery1BindParameter"
                  Binds="ExecuteWithParams1" Refresh="prepareModel"
                  RefreshCondition="#{empty requestScope.VariableChanged}"/>
    <iterator id="SelectDynamicQuery1ViewObjIterator"
                  Binds="SelectDynamicQuery1ViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>
    <invokeAction id="refreshDynamicQuery2BindParameter"
                  Binds="ExecuteWithParams2" Refresh="prepareModel"
                  RefreshCondition="#{empty requestScope.VariableChanged}"/>
    <iterator id="SelectDynamicQuery2ViewObjIterator"
                  Binds="SelectDynamicQuery2ViewObj" RangeSize="-1"
                  DataControl="DMSApplicationModule1DataControl"/>I now have a problem whereby everytime I change the value of the static LOV, multiple HTML components for the same ADF component are being generated (the LOVs are refreshed via PPR). The surprising thing is that this duplicating behaviour applies to all ADF components listed after the first dynamic LOV in the *.jspx source. For example, I have a <af:outputText="Test Text"/> component created after the first dynamic LOV. Each time the value in the static LOV changes, a duplicate HTML component is created. This also applies to the 'related' second dynamic LOV which is bound to a af:selectOneChoice component - multiple dropdown lists are created. I've checked with the browser's Page Source and there are actually multiple html components being generated with their own unique ADF-generated IDs. I've tried all different options for the Referesh and RefreshCondition attibutes in the second invokeAction element but nothing seems to eliminate this issue.
    Any suggestions about how I might create multiple dependent LOVs from the same bind variable that get refreshed when the selected value changes would be greatly appreciated.
    Thanks
    George

    Hi all,
    Just updating the thread on how I've overcome this issue. As it stood the manner in which I was trying to solve my use case, as described above, was creating an absolute mess. Then with a blank sheet of paper I quickly realised that a much simpler solution would be to create a whole series of master-detail VOs and build my components around them. Thankfully I haven't had any issues going down this path as yet.
    Cheers
    George

  • How to share a bind variable across multiple view objects?

    Hi, Can someone tell me if it's possible to share a bind variable among multiple view objects within an application module? My web page displays data from different VOs on different regions. But all data should be controlled by the same bind variable, which appears in all queries. How can I achieve this?
    Please help.

    Best to state your JDev version, and technology stack (eg. ADF BC) when posting.
    I can think of 2 approaches.
    1) Create a parent VO based on SELECT :bindVar FROM dual, then create links between your other VOs and the parent
    2) Create a AM client interface method that programatically sets the bind variable in each VO.
    Can you specify your use case? This one tends to come up when discussing effective from/to dated queries.
    CM.

  • Substitution vs bind variable

    Hi,
    Can you please give me the differences between substitution vs bind variables? I have done many searches and I am lost. Any examples would be great.
    Thanks.
    -U

    Perhaps what is needed is a simple example of both.
    h2. Substitution Variables
    The clue here is in the name... "substitution". It relates to values being substituted into the code before it is submitted to the database. These substitutions are carried out by the interface being used. In this example we're going to use SQL*Plus as our interface...
    So let's take a bit of code with substitution variables:
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn return varchar2 is
      2    v_dname varchar2(20);
      3  begin
      4    select dname
      5    into   v_dname
      6    from   dept
      7    where  deptno = &p_deptno;
      8    return v_dname;
      9* end;Now when this code is submitted...
    SQL> /SQL*Plus, parses the code itself, and sees the "&" indicating a substitution variable.
    SQL*Plus, then prompts for a value for that variable, which we enter...
    Enter value for p_deptno: 20
    old   7:   where  deptno = &p_deptno;
    new   7:   where  deptno = 20;... and it reports back that it has substitution the &p_deptno variable for the value 20, actually shoing us the whole line of code with it's value.
    This code is then submitted to the database. So if we look at what the code is, now created on the database we see...
    SQL> select dbms_metadata.get_ddl('FUNCTION', 'MYFN', USER) from dual;
    DBMS_METADATA.GET_DDL('FUNCTION','MYFN',USER)
    CREATE OR REPLACE FUNCTION "SCOTT"."MYFN" return varchar2 is
      v_dname varchar2(20);
    begin
      select dname
      into   v_dname
      from   dept
      where  deptno = 20;
      return v_dname;
    end;The database itself knows nothing about any substitution variable... it just has some fixed code with the value we supplied, that SQL*Plus substituted when we compiled it.
    The only way we can change that value is by recompiling the code again, and substituting a new value for it.
    Also, with substitution variables we don't necessarily have to use them just for 'values' (though that it typically what they're used for)... we can use them to substitute any part of the code/text that we are supplying to be compiled.. e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn(x in number, y in number) return number is
      2  begin
      3    return &what_do_you_want_to_return;
      4* end;
    SQL> /
    Enter value for what_do_you_want_to_return: y*power(x,2)
    old   3:   return &what_do_you_want_to_return;
    new   3:   return y*power(x,2);
    Function created.
    SQL> select dbms_metadata.get_ddl('FUNCTION', 'MYFN', USER) from dual;
    DBMS_METADATA.GET_DDL('FUNCTION','MYFN',USER)
    CREATE OR REPLACE FUNCTION "SCOTT"."MYFN" (x in number, y in number) return number is
    begin
      return y*power(x,2);
    end;It really does substitute the substitution variable, with whatever text you type.
    So, that's substitution variables. In summary they are variables that the user interface detects and prompts for text to substitute into the code before submitting it to the database.
    h2. Bind Variables
    Bind variables are a completely difference concept to substitution variables.
    Bind variables typically relate to SQL queries, and are a placeholder for values within the query. Unlike substitution variables, these are not prompted for when you come to compile the code.
    Now there are various ways of supplying bind variables, and I'll use a couple of examples, but there are more (such as binding when creating queries via the DBMS_SQL package etc.)
    In the following exaxmple:
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn(p_deptno in number) return varchar2 is
      2    v_dname varchar2(20);
      3    v_sql   varchar2(32767);
      4  begin
      5    v_sql := 'select dname from dept where deptno = :1';
      6    execute immediate v_sql into v_dname using p_deptno;
      7    return v_dname;
      8* end;
    SQL> /
    Function created.The ":1" is the bind variable in the query.
    If you examine queries running in the database you will typically see bind variables represented as :1, :2, :3 and so on, though it could be anything preceded by a ":" such as :A, :B, :C, :X, :FRED, :SOMETHING etc.
    When the query is passed to the SQL engine (in this case by the EXECUTE IMMEDIATE statement), the query is parsed and optimised and the best execution plan determined. It doesn't need to know what that value is yet to determine the best plan. Then when the query is actually executed, the value that has been bound in (in this case with the USING part of the execute immediate statement) is used within the execution of the query to fetch the required data.
    The advantage of using bind variables is that, if the same query is executed multiple times with different values being bound in, then the same execution plan is used because the query itself hasn't actually changed (so no hard parsing and determining the best plan has to be performed, saving time and resources).
    Another example of using bind variable is this:
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn(p_deptno in number) return varchar2 is
      2    v_dname varchar2(20);
      3  begin
      4    select dname
      5    into   v_dname
      6    from   dept
      7    where deptno = p_deptno;
      8    return v_dname;
      9* end;
    SQL> /
    Function created.Now, this isn't immediately obvious, but what we have here is the ability of the PL langauge to seamlessly integrate SQL within it (giving us PL/SQL). It looks as though we just have an SQL statement in our code, but in reality, the PL engine parses the query and supplies the query to the SQL engine with a bind variable placeholder for where the PL variable (parameter p_deptno in this case) is within it. So the SQL engine will get a query like...
    select dname
    from   dept
    where  deptno = :1and then the PL engine will handle the binding of the value (p_deptno) into that query when it executes it, as well as dealing with the returning value being put INTO the PL variable v_dname. Again the SQL supplied to the SQL engine can be optimised and re-used by code because it isn't hard coded with values.
    So, here, the binding of values is implicit because the PL engine is removing the need for us to have to code them explicitly.
    The other advantage of using bind variables is that you don't have to worry about the datatypes.
    Often we see people creating code such as this (going back to a similar dynamic SQL example)...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn(p_hiredate in date) return number is
      2    v_empno number;
      3    v_sql   varchar2(32767);
      4  begin
      5    v_sql := 'select empno from emp where hiredate = to_date('||to_char(p_hiredate,'DD/MM/YYYY')||',''DD/MM/YYYY'')';
      6    execute immediate v_sql into v_empno;
      7    return v_empno;
      8* end;
    SQL> /
    Function created.... where the developer is trying to concatenate in a date or varchar variable with the appropriate single quotes and formatting required to make the SQL make sense. Not only does that prevent the SQL explain plan from being re-used with different values, but it makes the code hard to maintain and get right in the first place (as well as leaving things open to SQL injection)
    But, with bind variable, that's not necessary... simply doing...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function myfn(p_hiredate in date) return number is
      2    v_empno number;
      3    v_sql   varchar2(32767);
      4  begin
      5    v_sql := 'select empno from emp where hiredate = :1';
      6    execute immediate v_sql into v_empno using p_hiredate;
      7    return v_empno;
      8* end;
    SQL> /
    Function created.... is all that is needed.
    The SQL engine knows that it is expecting a DATE datatype for the value because of what it's being compared against, and the USING statement is supplying a value of DATE datatype. No messy need to play with date formats or quotes etc. it just simply works. (and the same with other datatypes).
    So, that's bind variables. In summary they are placeholders in queries that allow SQL queries to be soft parsed rather than hard parsed when the query is re-used, help prevent SQL injection, and allow for the values to be supplied easily and seamlessly by the issuing code.

  • Create collection from query with bind variable

    Apex 4.0.2
    Per Joel Re: Collection with bind variable the apex_collection.create_collection_from_query_b supports queries containing bind variable references (:P1_X) but I am not sure how to use this feature, the documentation doesn't have an example, just the API signature for the overloaded version has changed.
    If the query contains 2 bind variable references to session state (:P1_X and :P1_Y), can someone please show an example of what to pass in for the p_names and p_values parameters to the API?
    Thanks
    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)
        ;

    VANJ wrote:
    Apex 4.0.2
    Per Joel Re: Collection with bind variable the apex_collection.create_collection_from_query_b supports queries containing bind variable references (:P1_X) but I am not sure how to use this feature, the documentation doesn't have an example, just the API signature for the overloaded version has changed.
    If the query contains 2 bind variable references to session state (:P1_X and :P1_Y), can someone please show an example of what to pass in for the p_names and p_values parameters to the API?Not tried it, but guessing 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')))

  • Maximum Size of bind variables/model names in a SPARQL query

    I was wondering what the maximum field size is for a bind variable (?'' being used in the subject or object within a triple) in a SPARQL query using the Jena Adapter for Oracle? The reason for this is that I keep getting Oracle exception (ORA-00972: identifier is too long) when executing queries.
    The other question dealt with the max size of the model names? Is there anyway to increase this length by extending certain classes within the Jena Adapter for Oracle?
    Thanks,
    Rahul

    Hi,
    For model names, because we use model names together with some suffixes to create namespace tables, application tables, and indexes, the length
    has to be shorter than 30 bytes - 11 bytes = 19 bytes.
    Note that 30 bytes limit is imposed by Oracle database. You cannot create a table with a name longer than 30 bytes.
    11 bytes is the maximum suffix length imposed by Jena Adapter. We are considering to reduce it to 4 for the next Jena Adapter release.
    For variable names, because we translate SPARQL to SQL queries (and variable name to column alias), there is the same 30 bytes limit.
    Note that there are suffixes for variable names as well. For example, $RDFVID, $RDFLTYP, ... These suffixes are used internally.
    Some simple tests for illustration purpose.
    SQL> create table a23456789012345678901234567890(i int);
    Table created.
    SQL> create table a234567890123456789012345678901(i int);
    create table a234567890123456789012345678901(i int)
    ERROR at line 1:
    ORA-00972: identifier is too long
    -- Assume table X has a column I
    SQL> select i as "v23456789012345678901234567890" from x;
    no rows selected
    SQL> select i as "v234567890123456789012345678901" from x;
    select i as "v234567890123456789012345678901" from x
    ERROR at line 1:
    ORA-00972: identifier is too long
    Hope it helps,
    Zhe Wu

  • How to querie with bind variable in findMode?

    Hallo,
    is it possible to use a querie with bind variable in findMode? And when how is it possible to initialize the bind variable?
    Any help is appreciated.

    Hi,
    bind variables can be linked from teh ADF binding to e.g. a managed bean, the sessionScope or other binding attributes via EL. So when you go into findMode and execute the query, the EL will grab the bindVariable values automatically.
    Frank

  • Bind variables in inner join queries

    Hi all,
    can we use bind variables in inner join queries?
    eg:
    INNER JOIN PRTY_LOC_CODE_T plc ON (ppt.PRTY_REC_ID = plc.PRTY_REC_ID and plc.HIST_CTRL_IND = *0*_ and plc.DEL_IND = *'N'*_)
    regards
    sunil

    Dear,
    can we use bind variables in inner join queries?Where are you using this join? if in a stored procedure or stored function than you don't have to care about your variables. It will be automatically considered as a bind variable
    within your static SQL (i.e in your stored procedure)
    Hope this helps
    Mohamed Houri

  • Report queries and bind variables - only header printing to PDF

    Hi,
    I created a simple report query for printing to PDF with 2 bind variables. I created a link to this report like this
    Print - the header information prints but none of the data.
    What am i doing wrong? I'm pretty sure it has s/t to do with the bind variables.
    IF a/o can please help, i'd really appreciate it.
    Thanks,
    Hindy

    is it possible to export your application page to apex server and you shall also create a userid as demo/demo and post the url so that we shall try the debug

  • Report Performance with Bind Variable

    Getting some very odd behaviour with a report in APEX v 3.2.1.00.10
    I have a complex query that takes 5 seconds to return via TOAD, but takes from 5 to 10 minutes in an APEX report.
    I've narrowed it down to one particular bind. If I hard code the date in it returns in 6 seconds, but if I let the date be passed in from a parameter it takes 5+ minutes again.
    Relevant part of the query (an inline view) is:
    ,(select rglr_lect lect
    ,sum(tpm) mtr_tpm
    ,sum(enrols) mtr_enrols
    from ops_dash_meetings_report
    where meet_ev_date between to_date(:P35_END_DATE,'DD/MM/YYYY') - 363 and to_date(:P35_END_DATE,'DD/MM/YYYY')
    group by rglr_lect) RPV
    I've tried replacing the "to_date(:P35_END_DATE,'DD/MM/YYYY') - 363" with another item which is populated with the date required (and verified by checking session state). If I replace the :P35_END_DATE with an actual date the performance is fine again.
    The weird thing is that a trace file shows me exactly the same Explain Plan as the TOAD Explain where it runs in 5 seconds.
    Another odd thing is that another page in my application has the same inline view and doesn't hit the performance problem.
    The trace file did show some control characters (circumflex M) after each line of this report's query where these weren't anywhere else on the trace queries. I wondered if there was some sort of corruption in the source?
    No problems due to pagination as the result set is only 31 records and all being displayed.
    Really stumped here. Any advice or pointers would be most welcome.
    Jon.

    Don't worry about the Time column, the cost and cardinality are more important to see whther the CBO is making different decisions for whatever reason.
    Remember that the explain plan shows the expected execution plan and a trace shows the actual execution plan. So what you want to do is compare the query with bind variables from an APEX page trace to a trace from TOAD (or sqlplus or whatever). You can do this outside APEX like this...
    ALTER SESSION SET EVENTS '10046 trace name context forever, level 1';Enter and run your SQL statement...;
    ALTER SESSION SET sql_trace=FALSE;This will create a a trace file in the directory returned by...
    SELECT value FROM v$parameter WHERE name = 'user_dump_dest' Which you can use tkprof to format.
    I am assuming that your not going over DB links or anything else slightly unusual?
    Cheers
    Ben

Maybe you are looking for