How to use bind variables using in  clause in SQL

Hi
Can any one help me in regards Bind variables usage using in clause in sql for String data?
thans

Are you looking for a dynamic IN list? As in something like this:
SELECT ... FROM .. WHERE some_col IN (<dynamic list of stuff that is always changing>)If so check this out:
[ How can I do a variable IN list?|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425]

Similar Messages

  • Using bind variable with IN clause

    My application runs a limited number of straight up queries (no stored procs) using ODP.NET. For the most part, I'm able to use bind variables to help with query caching, etc... but I'm at a loss as to how to use bind variables with IN clauses. Basically, I'm looking for something like this:
    int objectId = 123;
    string[] listOfValues = { "a", "b", "c"};
    OracleCommand command = new OracleCommand();
    command.Connection = conn;
    command.BindByName = true;
    command.CommandText = @"select blah from mytable where objectId = :objectId and somevalue in (:listOfValues)";
    command.Parameters.Add("objectId", objectId);
    command.Parameters.Add("listOfValues", listOfValues);
    I haven't had much luck yet using an array as a bind variable. Do I need to pass it in as a PL/SQL associative array? Cast the values to a TABLE?
    Thanks,
    Nick

    Nevermind, found this
    How to use OracleParameter whith the IN Operator of select statement
    which contained this, which is a brilliant solution
    http://oradim.blogspot.com/2007/12/dynamically-creating-variable-in-list.html

  • Can any one tell me how to use EXISTS clause inplace of IN operator.

    Hi All,
    Can any one tell me how to use EXISTS clause AND (JC.EMPL_ID, JC.EMPL_RCD) inplace of IN operator.
    SELECT COUNT (1)
    FROM SYSADM.OHR_PERS_CURR PC
    , SYSADM.OHR_JOB_CURR JC
    WHERE PC.EMPL_ID = JC.EMPL_ID
    AND (JC.EMPL_ID, JC.EMPL_RCD) in (
    SELECT HS.EMPL_ID, HS.EMPL_RCD
    FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
    WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
    AND OS.DB_LOGIN = USER)
    Thank you.

    SELECT COUNT (1)
    FROM SYSADM.OHR_PERS_CURR PC
    , SYSADM.OHR_JOB_CURR JC
    WHERE PC.EMPL_ID = JC.EMPL_ID
    AND EXISTS (
    SELECT null
    FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
    WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
    AND OS.DB_LOGIN = USER
    AND HS.EMPL_ID = JS.EMPL_ID AND HS.EMPL_RCD = JC.EMPL_RCD)
    But why ?
    Rgds.

  • How to use From clause as a block datasources

    Hi,
    I want to know how to use from clause as a block datasource.
    Could anyone give me an example to do that? I couldn't find it
    in the help file.
    I sincerely ask someone help me.
    Many thanks
    Diana

    Diana,
    I presume you are getting a "FRM-40505: error unable to perform
    query" when you try to execute query. I suggest you select the
    "Display Error" item from the "Help" menu to see the query that
    Oracle is generating. If the query that Oracle generates as a
    result of your "Query data source name" is not formed correctly,
    you will get the FRM-40505 error.
    Copy and paste the query that is displayed into SQLPLUS and test
    to see what happens when you try to execute the query from
    SQLPLUS. That will give you a better idea of what the cause of
    the problem is.
    From your example, a query that works should look like "select
    c_no from (select c_no from books)".
    Keep in mind that for blocks based on FROM clause, the query that
    produces the data is of the form :
    SELECT <all columns in the block>
    FROM <select statement entered in the "Query Data Source Name"
    blockproperty>
    The data source for the block is the select statement embedded in
    the from clause.
    Hope this helps.

  • How to enter bind variables in Calender SQL statement

    Hi,
    Anyone know how to include bind variables in Calender SQL statement. Let's say in sql statement below:
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    order by EMP.HIREDATE
    thanks.

    Hi,
    Here is the sql statement
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    where deptno = :dept
    order by EMP.HIREDATE
    Thanks,
    Sharmila

  • How to use OEM to moniter sql server 2000

    Hi,
    I need to learn How to use OEM to moniter sql server 2000.
    Can anyone help me and give me some website or documents
    to read?
    So I can learn to do this job.
    Thanks.

    See Note 115302.1 in Metalink.oracle.com
    in how to use OEM Diagnostic pack addon for SQL Server
    Or search for
    oem "user events"
    to build your own monitor script.

  • How to use sql "IN" operator with named bind variable in where clause ?

    Can one bind variable be used for the "IN" list ('1','2','3') ?

    rob,
    No worries. Glad it helped. Glad to see also that you're doing things right and trying to use bind variables ;)
    May I suggest adding "SOLVED" to the title of the original post?
    Best,
    John

  • How to default bind variable using session variable at run time

    Hi All,
    I have a requirement where all VO queries (multiple VOs) produce only records that meet a certain value.
    For example, I have three tables with 3 VOs and each of them has a one-to-many relationship to another table (let's call it ref table and this table has a field called release). One of the 3 VOs is a parent/master table, and the other two are child tables. I created a VO for master table that linked to the ref table and created a view criteria using the release (use bind variable) field from the ref table. The other child tables have their own VO that has view criteria that also linked to ref table using the release field.
    On the UI page, I created a query component and a table from the master table VO. I also dropped the child table VOs in a tabbed panel which partial triggered by the master table. When I ran a query for a 'release' (hint: ref table value), the table for master table was filled the correct records that meet the criteria. Unfortunately, the child tables were not correct due to the query didn't use the bind variable that filter only records for the same 'release' value as the master table.
    The question is how do I 'default' or dynamically set the bind variable on the child tables based on the selection criteria from the query component. I am thinking to set a session variable from the query and use it in the bind variable in the child table, but not sure how to do it.
    Any suggestion how to do it or better solution to achieve the same effect?

    Hi,
    How about creating a custom AMImpl method, that takes parameters as required, and set the bind variables for all the desired VOs and perform executeQuery on them.
    You could expose this as client interface, and then use the method as parameter form.
    Check this thread for ex.
    Re: Setting Attribute in View Object through Managed Bean
    -Arun

  • Using bind variables (in & out) with dynamic sql

    I got a table that holds pl/sql code snippets to do validations on a set of data. what the code basically does is receiving a ID and returning a number of errors found.
    To execute the code I use dynamic sql with two bind variables.
    When the 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 some more complex validations that need to do calculations or execute multiple queries, I'm running into trouble.
    I've boiled the problem down into this:
    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 doesn't really make any sense, but it's just to show you what the problem is. When I execute this code, I get the error
    ORA-6537 OUT bind variable bound to an IN position
    The error doesn't seem to make sense, :2 is the only IN bind variable, and it's only used in a where clause.
    As soon as I remove that where clause , the code will work again (giving me 61-61, in case you liked to know).
    Any idea whats going wrong? Am I just using the bind variables in a way you're not supposed to use them?
    I'm using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit

    Correction. With execute immediate binding is by position, but binds do not need to be repeated. So my statement above is incorrect..
    You need to bind it once only - but bind by position. And the bind must match how the bind variable is used.
    If the bind variable never assigns a value in the code, bind as IN.
    If the bind variable assigns a value in the code, bind as OUT.
    If the bind variable assigns a value and is used a variable in any other statement in the code, bind as IN OUT.
    E.g.
    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>

  • How to populate bind variable in view objects where clause in ADF faces

    I've got a page with 2 input items.
    The user manually enters the first value.
    On the second input item I have created a LOV for the item which opens in a popup. How do I restrict the data returned in the LOV using the value entered in the first input item. I have created a bind variable and have included it in the where clause for the view object but how do I populated it.

    Here is an example:
    Using the HR schema with the EMPLOYEES and DEPARTMENTS tables.
    Example is using ADF BC and created an EMPLOYEES entity with an updateable view object for page,
    and created a DEPARTMENTS view as a lookup
    (SQL: select department_id, department_name from departments where department_name = :DeptName)
    1: add method to the backing bean to filter the LOV
    public void getTextValueToFilterLOV(ValueChangeEvent valueChangeEvent) {
    Object value_from_form = valueChangeEvent.getNewValue();
    FacesContext fctx = FacesContext.getCurrentInstance();
    Application fapp = fctx.getApplication();
    JUFormBinding formBinding = (JUFormBinding)fapp.createValueBinding("#{bindings}").getValue(fctx);
    DCIteratorBinding dcBinding = (DCIteratorBinding)formBinding.get("DeptLOVIterator");
    ViewObject vo = dcBinding.getViewObject();
    vo.setNamedWhereClauseParam("DeptName",value_from_form);
    vo.executeQuery();
    2. add valueChangeListener to the inputText on the page with an id and autoSubmit="true"
    <af:inputText value="#{bindings.LastName.inputValue}" label="#{bindings.LastName.label}" binding="#{backing_DeptForm.inputText3}"
    id="inputText3"
    autoSubmit="true"
    valueChangeListener="#{backing_DeptForm.getTextValueToFilterLOV}">
    </af:inputText>
    3. reference the LOV with the id name on the partialTriggers property
    <af:selectOneChoice value="#{bindings.EmployeesUpdView1DepartmentId.inputValue}"
    label="#{bindings.EmployeesUpdView1DepartmentId.label}" binding="#{backing_DeptForm.selectOneChoice1}"
    id="selectOneChoice1"
    partialTriggers="inputText3">
    <f:selectItems value="#{bindings.EmployeesUpdView1DepartmentId.items}"
    binding="#{backing_DeptForm.selectItems1}"
    id="selectItems1"/>
    </af:selectOneChoice>
    Summary:
    When you entered a text (LastName), that value is passed into the backing bean method.
    The Bean method code will find the LOV Iterator and put the value into the bind variable.
    Cheers,
    Jim

  • How to use where clause with get statement in LDB programs

    Hi All,
    I am using logical databse in my report program.I am not getting how to use the where clause in the get statement is it possible to use?or if not possible only option is we should filter it after get statment is right?Can you please some body throw some idea on this?
    Regards
    Mahesh

    Hi,
    Reffer these links
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
    /people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
    reward if helpful
    Thanks,
    Suma.

  • How to use WHERE Clause in BPEL

    Hi ,
    i am trying to use where clause in DB adapter but its not working.
    my query is "select empname from employee where empid = &a"
    can any body tell me what is the reason its npt working?
    and how can i retrive data form DB?

    Hi,
    You are thinking perfectly fine. The solution what I suggested was
    select ename from emp where empno=?
    And the solution provided by you was
    SELECT first_name, last_name FROM per_all_people_f WHERE person_id = #p_person_id
    There is no problem with the above mentioned select statements.
    I just want to say that if you see closely, internal logic changes #parameter name to ?. So both the logics are right.
    Cheers,
    Abhi...

  • 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

  • Error bind variable with "like %" clause ?

    Hello everybody;
    I would like to know how to do a like clause to bind variables, with this code i obtain 'ORA-00933: SQL command not properly ended' error
    v_query:= 'UPDATE ' || collection(i) ||' SET REF_PLAN=:quatre_champ WHERE FAM_SIM like ''%'':prem_champ''%'' AND PRISE_V1P like ''%'':deux_champ''%'' AND BROCHE_V1P like ''%:trois_champ%''';
                                  EXECUTE IMMEDIATE v_query USING quatre_champ,prem_champ,deux_champ,trois_champ;Maybe my " ' " are in a bad positions ?
    Thanks for your help, regards.

    Hi,
    try this
    v_query :=
             'UPDATE '
          || collection (i)
          || ' SET REF_PLAN =:quatre_champ WHERE FAM_SIM like'|| '''%:prem_champ%'''
          || ' AND PRISE_V1P like' || ''' %:deux_champ%'''
          || ' AND BROCHE_V1P like'||''' %:trois_champ%;'''
    Of course not tested
    Any efforts to give sample data and help us recreated the problem will be appreciated.
    Cheers!!!
    Bhushan

  • How to get binding variables from request

    We are trying to use html-db to develop an application which need to get values from user request to use in the queries, i.e. we will have pages depend on several binding variables and the value of these variables will be provided by the user through get/post request. Because the request will be initialed by another application so to use a form to collect the values is not an option.
    I am a html-db newbie. Does anyone here know how to do that?

    you're right in thinking this is a bit of a newbie html db question. it's a pretty straightforward matter to set up a report in html db that runs off of bind variables that can be set from a URL. you can see a pretty simple example on the first page of our "Sample Application" that's available to install into your workspace. try taking a look at that to see what i mean. you can install the Sample Application by clicking the "Review Demonstration Applications" link that's available right after logging into htmldb.oracle.com. that resulting screen lets you create (or re-create) the Sample App in your workspace. once it's installed, take a look at how the report on page 1 calls the first report on page 201. that report on 201 is dependent on a bind variable, :P202_CATEGORY, that's set from the URL. this particular URL is generated from the report on page 1, but it could just as easily have been generated from your other application. when you look at this example, the two key points to pay attention to are the 1) syntax used in the URL to set the bind variable (which is explained in our online help at http://htmldb.oracle.com/i/doc/mvl_fund005.htm#sthref357) and 2)the way in which that bind variable is referenced in the first sql query region on page 201. take a look at those when you get a chance, and let us know if you have further questions.
    thanks,
    raj

Maybe you are looking for

  • Pass values to se16 through report

    Hi, I am working on a requirement in which I am getting purchase order number (POs) from user through select options in an internal table and i need to display all the fields of EKBE table for those POs. For this I am using SE16. I want to pass all t

  • Subsequent Consolidation

    Hi, We have a question about subsequent consolidation. If we have no variations in the % of participation, the only variations we will have are in the net income of the investee units and in the Currency Translation differences item. We believe that

  • Trojan virus on computer. Can't open any programs.

    Hi, The other day my kapersky antivirus detected a trojan on my Toshiba laptop. I deleted it. I also downloaded and ran malwarebytes. The computer has slowed down dramatically. I can't even open any program's now because the cursor shows as loading.

  • Crashing when loading songs

    7.2.1 I had one song open, and asked it to open another while keeping the first open (admittedly they're both big songs, lots of VSL EXS's) and it hung while opening the 2nd song. I Force Quit, and now it won't open either song, gets so far thru the

  • Z3 Compact Updates

    Hi, I've just picked up an unlocked version of the Z3 compact from Amazon. This is my first Sony android device so in unfamiliar territory. I've been reading that apps like Whats new have been updated to 1.4+and it removes it from the swipe up gestur