Bind Variables...Urgent

Thanks!
I build a SQL statement, PARSE and Execute...
Begin :l_result := Test(pa01=>':pa01',pa02=>':pa02'); End;
I am binding ':pa01', ':pa02'
When I try to Bind variables, it throws error "ORA-01036 illegal variable name/number".
Do I need to install any patch - current version Forms [32 Bit] Version 6.0.8.17.1 (Production)

Placeholders (:name) are bound by position in EXECUTE IMMEDIATE SQL statement. Hence Oracle does not consider multiple :p_comp_id in your statement to be the same thing. You would need to repeatedly bind them for each occurrence, or use an approach (DBMS_SQL.BIND_VARIABLE or EXECUTE IMMEDIATE PL/SQL block) which binds by name or position / name.
In the case of the above example you would have a USING clause similar to the below (Note that I am unable to test this).
EXECUTE IMMEDIATE sql_statement
   USING p_comp_id, p_comp_id, p_site_id,
      p_site_id, p_task_type, p_comp_id,
      p_po_no, p_ebiz_sku_no, p_sku_status,
      p_lp, p_batch_no, p_comp_id;

Similar Messages

  • How to use the bind variable in custom.pll

    Hi,
    How to use the bind variable in custom.pll.Its through error.
    any one gem me.
    very urgent.
    M.Soundrapandian.

    Hello,
    Please, ask this kind of questions in the e-business forum.
    Francois

  • Error when Setting value to Bind variable in View Link used in HGrid

    Hi
    I have requirement to pass profile id as bind variable, I have created a VO based on below Query.
    select 'N' Is_Selected, 'N' Is_Already_Selected, 'N' Is_Selected_Copy, a.*
    from XXPA_STATE_CONST_DTLS_V a, xxpa_state_const_dtls b
    where a.child_id = b.child_id(+)
    and b.profile_id(+) = :1
    View Link Query that is being generated is
    SELECT * FROM (select 'N' Is_Selected, 'N' Is_Already_Selected, 'N' Is_Selected_Copy, a.*
    from XXPA_STATE_CONST_DTLS_V a, xxpa_state_const_dtls b
    where a.child_id = b.child_id(+)
    and b.profile_id(+) = :1) QRSLT WHERE PARENT_ID = :Bind_ChildId
    it Shows Errors as
    ## Detail 0 ##
    java.sql.SQLException: Missing IN or OUT parameter at index:: 1
    could anyone tell what could be the wrong. Do we need to set bind variable in view link Explicitly? or any other alternative.
    Its very Urgent.
    Regards
    Vimal

    Hi,
    I have faced similar problem some time ago. I could not find any solution except removing bind parameters in where clause. I tried to change binding style but it also didn't work. I think the problem is caused by view link's where clause.

  • How to assign sessionscope variable to the bind variable in Query of VO

    Hi all,
    I want to know how to assign a sessionscope variable in the binvariable of Query in VO
    My sessionscope variable holds the value of currently selected column in the table. eg:empname of the currently selected column which is in empdetails table...
    I want display the schemes available for the selected employee in the next table..The schemes are in another table named empschemes which has the empname and empschemes as column
    I have created a vo for empschemes table with bind variable 'scheme_bind'..I need to set the sessionscope variable '#{sessionScope.empname}" to the bind variable.
    Its urgent,..Pls do reply asap
    Thanks in advance
    Nasrin

    HI,
    You can use
    adf.context.sessionScope.get("YourSessionVariable")this code for assigning VO's bind variable value.write this code where you create bind variable and do not forget click on expression radio button.
    Rafat

  • HELP: Bind Variable does't work in SQL statement

    I am trying to connect a text item bind variable into the where
    clause of an SQL statement. Specifically into an INSERT
    statement and SELECT statement. It gives me an message box
    error, saying it is unable to insert. There is no Oracle error
    number associated with it. Is this a bug? Has this happened to
    anyone else. PLEASE HELP! URGENT!
    null

    I assume this is a forms problem. You need to check out the
    dbms_error_code and dbms_error_text to get your oracle error.
    You can trap and report these types of errors using an on-error
    trigger. Also, if you are using the default menu then check
    out help -> display error immediately after the form reports
    unable to insert ...... This should give you enough information
    to solve your problem, or at least point you in the right
    direction.
    Daniel Jensen (guest) wrote:
    : I am trying to connect a text item bind variable into the where
    : clause of an SQL statement. Specifically into an INSERT
    : statement and SELECT statement. It gives me an message box
    : error, saying it is unable to insert. There is no Oracle error
    : number associated with it. Is this a bug? Has this happened to
    : anyone else. PLEASE HELP! URGENT!
    null

  • Need help in Bind variable in AF Query LOV

    Hi,
    i have one problem with bind variable, if i use bind variable in the LOV VO Query then my result is not coming, if there is not bind variable it's working fine and if i use the bind variable in the LOV search option then it's working fine but if i hide the bind variable and set the value in AM prepareSesstion method the LOV is not returning any value. I try to return the values also all values are also coming but those values are not setting to AF Query Attribute.
    Query is:
    select substr(d.description,0,40) description
    from cm_system_users a,
    cm_user_responsibilities b,
    cm_responsibility_processes c,
    cm_processes d
    where a.nt_login =:B_NT_LOGIN
    and a.user_id = b.user_id
    and trunc(sysdate) between b.eff_date and nvl(b.exp_date,sysdate + 1)
    and b.RESPONSIBILITY_ID = c.RESPONSIBILITY_ID
    and c.process_type = d.process_type
    and d.enabled_flag = 'Y' order by d.arguments_flag
    AM Method:
    CmProcessViewImpl vo = getCmProcessView();
    String nt_login = getUserPrincipalName();
    vo.setNamedWhereClauseParam("B_NT_LOGIN", nt_login.toUpperCase());
    vo.executeQuery();
    Can any one help me in this. it's urgent for me.

    This is a little underdescribed. IIUC, the view object in question is being used as a target for a view accessor, correct? (Otherwise you'll have to be more explicit about what you mean by "Query LOV".
    If I'm right, there are two possibilities:
    1) You are using a VO instance in a shared application module instance. If so, make sure your code is in the prepareSession() for that application module class if it's session dependent (as it seems to be below), you need to make sure the application module instance is shared at session scope.
    2) You've based the view accessor directly on the VO definition. This basically creates an anonymous VO instance; I don't think there's any way to use prepareSession() to set a bind variable on such an instance (which won't be created until the accessor is first used). You might be able to get by with putting similar code into the view object class' create() method, but I haven't tested this.
    If your code is in your primary application module class (as opposed to the class for a shared AM instance), the problem here is that getCmProcessView() returns the VO instance from that application module instance's design-time data model, which is never used by view accessors.
    By the way, why do you need to do this in prepareSession() instead of at the view accessor level? I believe you can get the logged in user name (for the view accessor) in with the groovy expression
    viewObject.DBTransaction.session.userPrincipalName
    or possibly just
    DBTransaction.session.userPrincipalName
    (despite this involving DBTransaction, it returns the web app user name, not the DB username).
    That's a 100% declarative solution, if you don't count the Groovy expression as non-declarative.
    If you're afraid of a user executing the LOV (somehow) before the bind variable value gets set, just ensure that the bind variable is marked "required".

  • 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

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

  • Can I use bind variable instaed of writing static COLUMN Name

    Hi , I am having a table containing id and column names, the data is stored against that id in other tables. Now I wish to update data into another table so that it goes into apppropriate column without using decode function.
    I am trying to do this:
    EXECUTE IMMEDIATE 'update TEST set :1 = :2
    where PROJECT_ID= :3 and UNIQUE_ID= :4' using P_DEST_COLUMN, P_TEXT_VALUE, P_PROJ_ID, P_TASK_UID;
    the values P_DEST_COLUMN, P_TEXT_VALUE, P_PROJ_ID, P_TASK_UID are populated using a cursor in PL/SQl
    Is this statement valid? If not can you tell me how to do it as I am getting some error I am unable to comprehend.
    thanks
    Rishabh

    Column names cannot be substituted at run-time as bind variables. If you need to specify the column name at run-time, you'd need to construct a new string and execute that string dynamically, i.e.
    EXECUTE IMMEDIATE 'UPDATE test SET ' || p_dest_column || ' = :1 ' || ...From a data model standpoint, storing column names as data elements in another table is generally a rather poor idea. It's likely to make ad-hoc reporting nearly impossible and to cause a lot more parsing than would otherwise be required.
    Justin

  • Dynamic sql and bind variables

    Hi,
    I have a stored procedure which filters a table on 5 five columns. The filters come from the input parameters,
    and these 5 parameters can come in any combination, I mean some of them may be null and some of them may not be null.
    So I constructed the where filter of the query with IF blocks like the following:
    dynamic_query := 'select * from TESTTABLE where 1= 1';
    IF (P1 is not null) THEN
    dynamic_query := dynamic_query || ' AND column1 = :1';
    END IF;
    IF (P2 is not null) THEN
    dynamic_query := dynamic_query || ' AND column2 = :2';
    END IF;
    IF (P3 is not null) THEN
    dynamic_query := dynamic_query || ' AND column3 = :3';
    END IF;
    IF (P4 is not null) THEN
    dynamic_query := dynamic_query || ' AND column4 = :4';
    END IF;
    IF (P5 is not null) THEN
    dynamic_query := dynamic_query || ' AND column5 = :5';
    END IF;
    OPEN CUR_OUT FOR dynamic_query USING P1, P2, P3, P4, P5;
    The problem is how can I construct the USING and bind parameters, I cannot use "USING P1, P2, P3, P4, P5" because some of bind variables
    may not be in dynamic query if the input parameters are null. Is there a way to overcome this problem without writing all the 2 ^ 5 combinations?
    Any help is greatly appreciated.

    here it is in the Tomer Cohen way:
    IF (P1 is not null) THEN
    dynamic_query := dynamic_query || ' AND column1 = :1';
    ELSE
    dynamic_query := dynamic_query || ' AND  :1 IS NULL';
    END IF;
    IF (P2 is not null) THEN
    dynamic_query := dynamic_query || ' AND column2 = :2';
    ELSE
    dynamic_query := dynamic_query || ' AND  :2 IS NULL';
    END IF;
    IF (P3 is not null) THEN
    dynamic_query := dynamic_query || ' AND column3 = :3';
    ELSE
    dynamic_query := dynamic_query || ' AND  :3 IS NULL';
    END IF;
    IF (P4 is not null) THEN
    dynamic_query := dynamic_query || ' AND column4 = :4';
    ELSE
    dynamic_query := dynamic_query || ' AND  :4 IS NULL';
    END IF;
    IF (P5 is not null) THEN
    dynamic_query := dynamic_query || ' AND column5 = :5';
    ELSE
    dynamic_query := dynamic_query || ' AND -1 = :5';
    END IF;
    OPEN CUR_OUT FOR dynamic_query USING P1, P2, P3, P4, P5;Amiel Davis

  • Bind variables and Dynamic sql

    I have this function which works only when i'm not passing bind variables. The moment i add bind variables it is not able to execute the function.
    Oracle Db Version: 8.1
    Thanks
    Source Code
    FUNCTION TestFunction( In_Test_id in Number,
    In_Asof in Date )
    Return ScoreType
    IS
    LvScore ABC.LV_SCORE.SCORE%TYPE;
    DVScore ABC.LV_SCORE.SCORE%TYPE;
    Begin
    EXECUTE IMMEDIATE
    'SELECT SCORE,DVSCORE
    FROM
    SELECT SCORE,DVSCORE
    DENSE_RANK() OVER (PARTITION BY TEST_ID ORDER BY ASOF_DT DESC) AS score_RANK
    FROM ABC.LV_SCORE
    WHERE TEST_ID = :x
    AND ASOF_DT <= :y
    ) WHERE score_RANK = 1'
    INTO LvScore,DVScore
    USING In_tEST_ID,In_Asof;
    Return ScoreType( LvScore,
    DVScore);
    End;

    It just keeps on executing for sometime and then disconnects itself from database What was the indication that told you that it disconnected? Was there a visible indication of this disconnect?
    Did you get ORA-03113?
    ===========================================
    ORA-03113: end-of-file on communication channel
    Cause: The connection between Client and Server process was broken.
    Action: There was a communication error that requires further investigation. First, check for network problems and review the SQL*Net setup. Also, look in the alert.log file for any errors. Finally, test to see whether the server process is dead and whether a trace file was generated at failure time.

  • Using bind variable in dynamic where clause and concatenate with query

    Hi,
    In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
    Is it possible to pass values to the bind variable through the dynamic variable/value?
    Please advise
    Thanks in advance
    Siva
    IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
    My query is like this
    open Out_Main FOR SelectQuery USING optional_using

    Thanks for reply,
    In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
    Please advise...
    IF in_assignedAppFlag IS NOT NULL THEN
              IF in_assignedAppFlag = 'Y' THEN
                   optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
              optional_using := ' in_appFuncGroup'||',in_currentUserID';          
              ELSe
                   IF in_isSupervisor = 0 THEN
                        optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID';
                   END IF;
              END IF;
         ELSE
              IF in_isSupervisor = 0 THEN
                   optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
                   optional_using := ' in_appFuncGroup'||',in_currentUserID';
              END IF;
         END IF;
         IF in_appFuncGroup IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
         END IF;
         IF in_queue_id IS NOT NULL THEN
              optional_where := optional_where || ' AND b.QUEUE_ID = :d';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
         END IF;
         IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
         IF in_sourceCode IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode';
         END IF;
         IF in_logo IS NOT NULL THEN
              optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
         END IF;
         IF in_firstName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
         END IF;
         IF in_surName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
         END IF;
         IF in_retreival_id IS NOT NULL THEN
              optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
         END IF;

  • How to update bind variable and restrict values in a Model Driven LOV?

    Hi Guys,
    Using JDev 11.1.1.2.0
    I've recreated an excellent Frank Nimphius article about restricting values derived from a model driven LOV (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/44-restrict-lov-169186.pdf)
    But my bind variable isn't updating. Deleting the bind variable gets me the entire LOV. Activate the code below and insert a bind variable into the where clause like Frank says and I get nothing back. Bind variable is blank. Any ideas? Code wasn't supplied with the article. It seems simple enough but the bind variable isn't updating in the SQL, even though the updated value shows up here...
      public void onLovLaunch(LaunchPopupEvent launchPopupEvent)
        BindingContext bctx = BindingContext.getCurrent();
        BindingContainer bindings = bctx.getCurrentBindingsEntry();
        FacesCtrlLOVBinding lov = (FacesCtrlLOVBinding)bindings.get("DepartmentId");
        lov.getListIterBinding().getViewObject().setNamedWhereClauseParam("deptId","60");
        System.out.println("lov name: " + lov.getName().toString());
        System.out.println("lov Param Attrs: " + lov.getListIterBinding().getViewObject().getNamedWhereClauseParams().getAttribute("deptId").toString());
        System.out.println("lov View Object: " + lov.getListIterBinding().getViewObject().getName().toString());
        System.out.println("lov IterBinding: " + lov.getListIterBinding().getName().toString());
       }Gets me ...
    lov name: DepartmentId
    lov Param Attrs: 60
    lov View Object: _LOCAL_VIEW_USAGE_lov_model_queries_EmployeesView_DepartmentsView
    lov IterBinding: DepartmentIdList_2

    That's a good idea, but it's still not working. Here is how I implemented it. It might be different from your suggestion as I'm still pretty new to this.
    I have a recursive tree table. You select a node. You then click a button which calls the listener below. "findParents" is a method call to the AppModuleImpl class and it finds all parent nodes of your selection. "restrictPartBomLOV", also of the AppModuleImpl class, then modifies the model driven lists' View Object (partBomLOV) to exclude those parent node values.
    The resulting model driven LOV on the popup should be updated, yeah? But it still isn't udpating. If I manually type in the updated Where clause in PartBomLOV.xml query tab, it works, but it doesn't programmatically.
      public void insertPopupFetchListener(PopupFetchEvent popupFetchEvent)
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = bindings.getOperationBinding("findParents");
        parents = (List)operationBinding.execute();
        operationBinding = bindings.getOperationBinding("restrictPartBomLOV");
        operationBinding.execute();
       public void restrictPartBomLOV(List parents)
          ViewObjectImpl vo = getPartBomLOV();
          String wcl = "";
          Object[]   p = parents.toArray();
          for(int i = 0; i < p.length; i++)
             if (i == 0)
                wcl = wcl + "PNUM <> '" + p.toString() + "'";
    else
    wcl = wcl + "AND PNUM <> '" + p[i].toString() + "'";
    vo.setWhereClause(wcl);
    System.out.println(vo.getWhereClause().toString());
    vo.executeQuery();
    Edited by: LovettWB on Nov 11, 2010 11:23 PM

  • Can Oracle convert literals to bind variables?

    Good morning everyone.
    I have a procedure similar to this in our database:
        FUNCTION Get_Tag_Element_Id_For_Set(Element_Attr_Id_Table_In   in    ATTRIBUTE_TABLE_ID_TAB) RETURN NUMBER IS
          v_Select_Statement                    VARCHAR2(32767);
          v_Element_Id                             ELEMENT.Element_Id%TYPE;
        BEGIN
          FOR I IN 1..Element_Attr_Id_Table_In.COUNT LOOP
            IF v_Select_Statement IS NULL THEN
              v_Select_Statement := 'SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Element_Attribute_Id = ' || Element_Attr_Id_Tab_In(i);
            ELSE
              v_Select_Statement := v_Select_Statement || ' intersect ' ||
                                    'SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Element_Attribute_Id = ' || Element_Attr_Id_Table_In(i);
            END IF;
          END LOOP;
          EXECUTE IMMEDIATE v_Select_Statement INTO v_Element_id;
          RETURN v_Element_Id;
        END;What this does is to create a query similar to this:
    SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Tag_Element_Attribute_Id = 1 intersect
    SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Tag_Element_Attribute_Id = 2 intersect
    SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Tag_Element_Attribute_Id = 3 intersect
    SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Tag_Element_Attribute_Id = 4 intersect
    SELECT distinct Element_Id FROM ELEMENT_ATTRIBUTE_MANY_2_MANY WHERE Tag_Element_Attribute_Id = 5;
    I am using Dynamic SQL because the number of intersect pieces can vary from 1 to 15 and in the future it can grow.
    The problem that I have is that because the literals are part of the string, the query is being hard parsed every single time. In our production environment this means 100s of thousands of times per day which according to our DBA has added 15% plus to our average load. I know that I can come up with a rewrite to avoid this, but I was wondering if there is a parameter I can set at the session or at the database level where the database itself can convert this kind of query into one with bind variables.
    Thanks,
    Tom
    Edited by: Thomas Morgan on May 3, 2013 8:21 PM

    Thomas Morgan wrote:
    Basically I have an XML document.
    The document has ELEMENTS.
    ELEMENTS can have attributes.
    There is a many to many relationship between ELEMENT and ATTRIBUTES so I have a XREF table to represent this relationship.
    When I receive a new document, I need to determine if a group of ATTRIBUTES already exist together in the XREF table so I have to find their common ELEMENT_ID or NULL in which case I would create a new ELEMENT and associate the new set of attributes to the new ELEMENT.
    Since the number of attributes can vary from 1 to around 15 for now, I had to dynamically build the query that find the common ID(intersect) if it exists.
    Here is some DDL and inserts:
    CREATE TABLE ELEMENT(ELEMENT_ID NUMBER NOT NULL);
    CREATE TABLE ELEMENT_ELEMENT_ATTRIBUTE_XREF(Element_Id NUMBER NOT NULL, Element_Attribute_Id NUMBER NOT NULL);
    ALTER TABLE ELEMENT_ELEMENT_ATTRIBUTE_XREF ADD CONSTRAINT ELEMENT_ATTR_MANY_2_MANY_PK PRIMARY KEY(Element_Id, Element_Attribute_Id);
    ALTER TABLE ELEMENT ADD CONSTRAINT ELEMENT_PK PRIMARY KEY(Element_Id);
    INSERT INTO ELEMENT VALUES(1);
    INSERT INTO ELEMENT VALUES(2);
    INSERT INTO ELEMENT VALUES(3);
    INSERT INTO ELEMENT VALUES(4);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(1, 1);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(1, 2);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(2, 1);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(3, 1);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(3, 3);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(3, 4);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(3, 5);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(4, 6);
    INSERT INTO ELEMENT_ELEMENT_ATTRIBUTE_XREF VALUES(4, 7);
    So for instance if I passed an array (Attribute ID Tab) containing ELEMENT_ATTRIBUTE_ID list 6 and 7 I would get 4 as the answer.
    Hope this helps,
    Thanks,
    TomAwesome, thanks!
    I'm not sure this works 100% for what you need, but I thought I'd give it a shot. I've used a built in array (sys.odcinumberlist) that you should have access to on your installation (assuming you have a relatively recent version of Oracle).
    I left out the part where you would loop through the array you are currently passing in to your procedure to build up this new array that you can use in a SQL statement.
    Cheers,
    create or replace procedure maybe_this
       in_list           sys.odcinumberlist
    is
       l_commonality     number;
    begin
       begin
          select
             distinct
                xref.element_id
          into
             l_commonality
          from
                table(cast(in_list as sys.odcinumberlist))  list
            ,  element_element_attribute_xref   xref
          where
             xref.element_attribute_id = list.column_value;
          dbms_output.put_line('match on element_id = ' || l_commonality);
       exception
          when too_many_rows or no_data_found
          then
             dbms_output.put_line('no match');
       end;
    end;
    ME_TUBBZ?exec maybe_this(sys.odcinumberlist(1,2));
    no match
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    ME_TUBBZ?exec maybe_this(sys.odcinumberlist(6,7));
    match on element_id = 4
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01

  • Null check for a bind variable in view criteria

    Hi, Greetings.
    I am using Jdeveloper 11.1.2.0.
    I have a view object, LocationsView, for locations table of the XE database.
    I want to apply a condition, ((:bind_var is null) or (:bind_var is not null and location_id = :bind_var), in this LocationsView.
    That is, I want to apply the condition only if the bind variable value is not null.
    How can I construct this condition using a declarative view criteria?
    Any help and hints on this regard is greatly appreciated.
    Regards,
    Guru K

    Hi,
    Thanks for the update and it is working perfectly fine.
    Now, how can I set the "ignore null values" option as checked if I am constructing the criteria programmatically using view criteria row and view criteria item at runtime.
    Thanks and regards,
    Guru K

Maybe you are looking for

  • Static Header followed by dynamic header in a single table

    static1 static2 static3 =[dynamic] Hi Experise, I need a static header followed by the dynamic one as shown above, tried a lot but not able to make it.Can you guys help me please ? thanks, Santhosh

  • Problem exporting in 16.9

    I am trying to export a short film in 16.9, its no propblem to do as a large file but I need to have it as a smaller file. Less than 150g. So when I select in export using qt, chose my codec, everything is fine, but when I select encode for broadband

  • Error in PCR !!!

    Hi, I have written the following rule to customize the partial period factor -* /803 Partial period factor 3   OUTWPABART Payroll type in VKey     1     2     3       VAKEYPRGSC           RTE=TADIVI Set           RTE-TASOLL Subtraction           RTE*

  • How to Deploy Forms on web and Run report in Web browser

    Hi all, I am wondering how to run forms from the web and run report on web .. can u pl. brief me out and tell any source if i can reach and study...

  • Variable Width profile for the brush tool keeps resetting

    This problem is baffling me. I'm fairly new to Illustrator so I would appreciate some help. I'm using Adobe Illustrator CS6 with a mouse rather than a pressure graphics tablet. When I create a stroke using the Paint brush tool I would like the stroke