VO - bind variable in where clause problem

Hi
I have Jdeveloper 12. I successfully connected to mySQL database which works in Oracle mode (PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER)
Next I created EO, VO (screenshot) and finally AM.
when I run Application Module and enter bind variable value I receive error (screenshot):
oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation.  Statement: SELECT EO_TMP.create_date,         EO_TMP.id,         EO_TMP.name FROM autoid.advert EO_TMP WHERE EO_TMP.id = :var1
## Detail 0 ##
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
Doesn anybody know hot to fix this issue?
Regards.

I decided to check if it is a mySQL driver so I've performed the same query using a below code and it works. This is definitely model configuration issue.
Connection con = null;
try{
Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/sakila?user=root&password=1qaz2wsx");
String selectSQL = "SELECT actor_id,first_name,last_name,last_update FROM actor WHERE actor_id = ?";
PreparedStatement preparedStatement = con.prepareStatement(selectSQL);
preparedStatement.setInt(1, 4);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String userid = rs.getString("ACTOR_ID");
String username = rs.getString("FIRST_NAME"); 
System.out.println(userid); 
System.out.println(username); 
}catch (Exception e){
System.out.println(e.toString());  

Similar Messages

  • Bind variable as where clause

    hello,
    we want to build an dynamic sql IR. so when a user logs into our application we have an page process that fills an application item :F_ITEM_WHERE with part of the where clause from an IR. On the page with the IR we have as region source something similiar to:
    SELECT test_api_per_cus.get_per_name(id_per_cus) as Customer,
    test_api_per_cus.get_per_cus_nr(id_per_cus) as "Cus.-Nr",
    vtr_nr AS "VS-Nr."
    id_vtr,
    id_per_cus
    FROM test_vtr
    WHERE test_vtr.id_grp = :F_ID_GRP
    AND test_vtr.id_per_cus IN
    *(SELECT id_per_cus*
    FROM viva_per_cus
    WHERE LEVEL BETWEEN test_api_per_emo_r_tree.get_per_emp_r_tree_from(:F_ID_PER_EMP,
    *:F_ID_GRP) AND*
    test_api_per_emp_r_tree.get_per_mit_r_tree_to(:F_ID_PER_EMP,
    *:F_ID_GRP)*
    START WITH per_cus_nr =
    test_api_per_emp_r_tree.get_per_emp_r_tree_tree(:F_ID_PER_EMP,
    *:F_ID_GRP)*
    CONNECT BY PRIOR per_cus_nr = per_cus_number
    AND PRIOR id_grp = :F_ID_GRP)
    AND EXISTS
    so we want outsourcing the marked part of the where clause into :F_ITEM_WHERE. The result is as following:
    SELECT test_api_per_cus.get_per_name(id_per_cus) as Customer,
    test_api_per_cus.get_per_cus_nr(id_per_cus) as "Cus.-Nr",
    vtr_nr AS "VS-Nr."
    id_vtr,
    id_per_cus
    FROM test_vtr
    WHERE test_vtr.id_grp = :F_ID_GRP
    AND test_vtr.id_per_cus IN *|| :F_ITEM_WHERE ||*
    AND EXISTS
    Here says Apex that the Query cannot be parsed...if we fill the item plus 'AND test_vtr.id_per_cus IN' so our statement looks like this:
    SELECT test_api_per_cus.get_per_name(id_per_cus) as Customer,
    test_api_per_cus.get_per_cus_nr(id_per_cus) as "Cus.-Nr",
    vtr_nr AS "VS-Nr."
    id_vtr,
    id_per_cus
    FROM test_vtr
    WHERE test_vtr.id_grp = :F_ID_GRP
    *:F_ITEM_WHERE*
    AND EXISTS
    the query can parse but after that running apex says: bind :F_ITEM_WHERE not possible
    Anyone got an solution for this? I think it´s only a syntax thing or something...
    Thanks Daniel
    Edited by: user12086353 on 14.09.2010 06:01

    When posting code on the forum, put {noformat}{noformat} (with the curly brackets and the word code in lowercase) above and below your code like this...
    {noformat}{noformat}
    SELECT *
    FROM emp
    {noformat}{noformat}
    It will then appear like this, preserving formatting...SELECT *
    FROM emp
    Please post your code, properly formatted of +exactly+ what you have put in the region source. I'm not convinced that you need dynamic SQL at all.
    Cheers
    Ben                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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

  • 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

  • Variable in where clause of the logical table

    Hi,
    is it possible to define a variable in "where" clause of rpd's physical table (table type - select)? If yes, pls elaborate the steps including how to refresh it with every end user's request?
    Thanks and Regards,
    Igor
    P.S.
    If not, is there any workaround?

    Nico
    thanks, but I am afraid that is not my case. I need to refresh variable value interactively with every query by a dashboard prompt. To illustrate my need just imagine a recursive SQL (defined as a view/logical table in rpd):
    SELECT ....
    FROM ...
    WHERE ...
    START WITH .... columnA=variable1
    CONNECT BY PRIOR .... and columnB=varariable2;
    or
    SELECT c1,c2,c3,c4 from tabA where c1='A' and c2=variable1
    union
    SELECT c1,c2,c3,c4 from tabA where c1='A" and c2='D' and c1 NOT IN ( SELECT c1 FROM tabA where c1='A' and c2=variable1 );
    So, what I want to do is to pass value(s) to my variable(s) every time when respective select (view) is executed. I see above selects are not typical ones the OBI EE is intended for but nevertheless I wonder if such kind of reports are possible to do in OBI EE.
    Thanks and Regards,
    Igor

  • Boolean variable in where clause

    Hello,
    Does anyone know if it possible to include
    BOOLEAN variable in where clause as following:
    is_in_group BOOLEAN;
    begin
    is_in_group :=
    portal30.wwsec_api.is_user_in_group (
    p_person_id => portal30.wwctx_api.get_user_id,
    p_group_id => portal30.wwsec_api.group_id('GROUPNAME')
    for x in(select start_time,title
    from ec_reservations
    where
    start_time >= '2004-JAN-01'
    and rv_target_type='PU'
    and is_in_group = true
    Thank You,
    Helena

    Well, let's try it, eh?
    SQL> conn scott/tiger
    Connected.
    SQL> CREATE OR REPLACE FUNCTION sal_test ( p_sal IN NUMBER) RETURN BOOLEAN IS
      2  BEGIN
      3     RETURN p_sal > 1500;
      4  END;
      5  /
    Function created.
    SQL> SELECT ename, sal
      2  FROM   emp
      3  WHERE  sal_test(sal) = TRUE;
    WHERE  sal_test(sal) = TRUE
    ERROR at line 3:
    ORA-00904: "TRUE": invalid identifier
    SQL> So this is what we find. BOOLEAN is not a vlid SQL datatype, at least for Oracle. This is a source of much wailing and gnashing ot teeth. I believe there are enhancement requests for it, but no signs on the horizon.
    In the example you give you need it. You would be better off doing this...
    is_in_group BOOLEAN;
    begin
    is_in_group :=
    portal30.wwsec_api.is_user_in_group (
    p_person_id => portal30.wwctx_api.get_user_id,
    p_group_id => portal30.wwsec_api.group_id('GROUPNAME')
    IF is_in_group = true THEN
       FOR  x IN (select start_time,title
                  from ec_reservations
                  where start_time >= '2004-JAN-01'
                  and rv_target_type='PU' )
       ...Otherwise you have to recast your function so it returns VARCHAR2 with values of 'TRUE' and 'FALSE' (or NUMBER returning 0 and 1, whatever).
    Cheers, APC

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

  • Setting bind values in where clause in ViewObjectImpl

    We want customize our views in a special manner. To look up for instance a text in the session langauge, we add a bind variable to the declared where clause of a VO:
    and text.lang = :lang
    Let's suppose, the actual value of the session language be known within ViewObjectImplementations. I want to set the bind value transparently within the ViewObjectImplementation rather than having to do it in every UI related client using this VO. Until now, I set the bind value whenever getViewObject or BuildWhereClause is called. This is sufficient for the AM Tester, but not for JClient forms using this VO (as a Not-all-values-bound exception is thrown), and I am not able to figure out by the documentation which methods of a VO are called when it is created and queried by a JClient form.

    See this web log posting on providing automatic default values for VO bind variables:
    http://radio.weblogs.com/0118231/2003/08/01.html#a127

  • Binding an SQL "where" clause to a field in the report.

    Hello everybody,
    I have made a crystal report that works fine. Now, I need to add a specific query to the report and drag and drop the returned fields in the report.
    The problem is that I need to add a query that contains a "Where" clause that is binded to a field already existing in the report, for example :
    SELECT T0.Field1,
                  T0.Field2,
                  T0.Field3
    FROM Table1 T0
    WHERE T0.Field4=(a field from a report)
    Is it possible to do it ? if yes, how can I do it.
    Thank you in advance for your further responds,
    Best Regards,
    - Youssef -

    Moved to Report Design forum
    You can't do it in that specific way. It would have to be done server side or use a subreport and then link the subreport on the field from the main report.
    Don

  • How can we use  form variable in where clause while personalization

    Dear,
    I have a requirment for using select in personalization, actully we have created temporary table, now we want to get data from select satatement on event"when-new-record-instance' trigger, now in action tab i have selected action which is property and message, in message column showing value "${item.q_res.transaction_id.value}" it shows on validate button but when this form variable use in action type(property) which is consist on select statement "=SELECT to_char(QTY) FROM TEST_TABLE where transaction_id = ${item.q_res.transaction_id.value}" system didn't get value pressing validate button although there is a single record in customize table while without where cluase was getting data perfectly.
    please advice.

    >
    I am looking for to decode the actual db value something in different for my report.
    like if A then Accepted
    elseif R then Rejected
    elseif D then Denied
    these conditions I have to check in where clause.
    >
    what are you trying to do?
    may be you are looking for
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and
       (decode(:code, 'A','Accepted') = <table_column>
        or
        decode(:code, 'R','Rejected') = <table_column>
       or
        decode(:code, 'D','Denied') = <table_column>
       )

  • [SQL] Where clause problem with subqueries

    Hi,
    I'm writing a query for an apex application where i have a field (P47_UNNR) for filtering. In my where clause I try to do this:
    ... AND qo.pk_id IN
    CASE
    WHEN :P47_UNNR IS NULL
    THEN
    (SELECT pk_id FROM quote_orders)
    ELSE
    (SELECT QOR.FK_QUOTE_ORDER_ID
    FROM QUOTE_ORDER_RIDS QOR
    JOIN
    RIDS RID
    ON RID.PK_ID = QOR.FK_RID_ID
    WHERE RID.NAME LIKE :P47_UNNR)
    END
    But it gives an error "ORA-01427: single-row subquery returns more than one row"
    I have tried multiple ways to get around this problem but don't seem to be able to do this. Does anyone have a suggestion on how to solve this?

    Hi Niels,
    First try with separating the query.
    First try with:
    CASE
    WHEN :P47_UNNR IS NULL
    THEN
    (SELECT pk_id FROM quote_orders)
    END;check SELECT pk_id FROM quote_orders this query returning only one values or not???
    Then try with
    CASE
    WHEN :P47_UNNR IS NULL
    THEN
    (SELECT pk_id FROM quote_orders)
    ELSE
    (SELECT QOR.FK_QUOTE_ORDER_ID
    FROM QUOTE_ORDER_RIDS QOR
    JOIN
    RIDS RID
    ON RID.PK_ID = QOR.FK_RID_ID
    WHERE RID.NAME LIKE :P47_UNNR)
    ENDCheck this
    SELECT QOR.FK_QUOTE_ORDER_ID
    FROM QUOTE_ORDER_RIDS QOR
    JOIN
    RIDS RID
    ON RID.PK_ID = QOR.FK_RID_ID
    WHERE RID.NAME LIKE :P47_UNNRquery returning one values or not??
    If those returns more than one value , the check whether there is any duplication value's present, remove that duplicate value from your table.
    if you cant remove just add rownum =1 condition in your where clause.
    Cheers,
    San

  • Where clause problem with sub-queries in forms 6i

    where is the best place to put a sub query?? I have been using the set block property, however when running a sub query an alternative method must be used. what are some other options?? I have tried to have the query directly in the data block property palette but to no avail...
    There are 2 tables project and assignment
    maximum resources cannot be exceeded therefore a count of employees
    on the assignment table establishes that there are open spaces on the project.
    This code Here is my code for my where clause on the data block
    project.resources_maximum >
    (Select Count(assignment.employee_ID)
    From assignment
    Where assignment.project_ID = project.project_ID
    group by assignment.project_ID
    and project.end_date>sysdate;
    I was reading that the project table must be defined in the from clause
    to have the query go row by row, otherwise multiple rows are returned
    however I cannot define the project in the from,
    could this be why this doesn't work???
    original SQL that does work
    Need to migrate this to forms
    Select project.project_ID
    from project
    Where project.resources_maximum >
    (Select Count(assignment.employee_ID)
    From assignment
    Where assignment.project_ID = project.project_ID
    group by assignment.project_ID
    and project.end_date>sysdate;

    Looking at your query that works at the bottom, I do not see any reason that you would need to include the Assignment table in the From list. Just use the same where clause in the form:
      Where project.resources_maximum
        > (Select Count(assignment.employee_ID)
           From assignment
           Where assignment.project_ID = project.project_ID
           group by assignment.project_ID  )

  • Where clause problem in a subquery

    I'll try to explain as detailed as possible.
    Given the following set of data and the parameters passed the query must only return one row;
    If the structure_chain is like the parameter passed, then select that row
    If not then strip out the first number in both the parameter and the column,
    e.i., '2.35364194.34889485' becomes '35364194.34889485'
    The select is what is currently in the code and so far I've not been able to get the (new) desired results - customer changed/enhanced requirements
    with TT as
        (select 1 row_no, 22794978 old_child_id, 51755902 new_child_id, '1.35364194' structure_chain from dual union all
         select 2, 22794978, 51755899, '1.23576950' from dual union all
         select 3, 17872962, 51755893, '1.23576950' from dual union all
         select 4, 17872962, 51756065, '1.35364194.34880851' from dual union all
         select 5, 17872962, 51759249, '2.35364194.34880851' from dual union all
         select 6, 17872962, 51759248, '1.23576950.22795468' from dual union all
         select 7, 17872962, 51759250, '2.23576950.22795468' from dual )
    select * from tt
    where old_child_id = &1
    and   &2 like structure_chain ||'%'
    17872962 '2.35364194.34880851'   -- Return row_no 5 
    17872962 '1.23576950.22795468'   -- Return row_no 6 - this returns more than one
    17872962 '1.35364194.34880851'   -- Return row_no 4
    17872962 '2.23576950.22795468'   -- Return row_no 7
    22794978 '2.35364194.34889485'   -- Return row_no 1 - does not return anything
    22794978 '1.35364194.34889485'   -- Return row_no 1

    Hi,
    I'm not sure what you're asking.
    It would help if you posted the results you want as clearly as you posted the sample data. For each set of parametes, post the desired result set.
    I think you want to do two kinds of pattern matches, and return the results of the strictest one that has results.
    That is, if there is a match on all parts of structure_chain, then return the rows that match all parts.
    But if there is no match on all parts of structure_chain, then return the rows (if any) that match if we ignore the sub-atring before the first dot.
    That's an example of a Top-N Query , and here's one way to do it:
    WITH     got_r_num AS
         SELECT  tt.*
         ,     DENSE_RANK () OVER (ORDER BY  CASE
                                                WHEN  '&2'        LIKE structure_chain || '%'
                                    THEN  1
                                    ELSE  2
                                            END
                           ) AS r_num
         FROM     tt
         WHERE      old_child_id     = &1
         AND        SUBSTR ( '&2'
                     , INSTR ('&2', '.')
                     )                LIKE SUBSTR ( structure_chain
                                                  , INSTR (structure_chain, '.')
                                      ) || '%'
    SELECT     row_no, old_child_id, new_child_id, structure_chain
    FROM     got_r_num
    WHERE     r_num     = 1
    ;With parameters &1=17872962 and &2=1.23576950.22795468, the query above produces this output:
    `   ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
             3     17872962     51755893 1.23576950
             6     17872962     51759248 1.23576950.22795468because both rows matched the given &2, including the '1.' at the beginning. (The query you posted gave the same results in this case.)
    With parameters &1=22794978 and &2=2.35364194.34889485, the query above produces:
        ROW_NO OLD_CHILD_ID NEW_CHILD_ID STRUCTURE_CHAIN
             1     22794978     51755902 1.35364194because there was no match when considering the '2.' at the beginning of &2, but the row shown does match when we ignore the '2.'.
    The WHERE clause in the sub-query narrows the result set down to rows that meet at least the looser match reuirement.
    The CASE expression ranks each row as 1 if it meets the stricter requirement, and 2 if it only met the looser one.
    DENSE_RANK returns 1 for the lower of those numbers that was actually found.

  • Dynamic where clause problem?

    Hi all,
    I am using 4 parameters for the attrition rate report of an employee on the selection screen.
    Level
    Grade
    Position
    Salary Range (pa0008-ansal)
    i have filled the values of level, grade, position, from database tables at the initialization event.
    And for the salary range i hardcoded them to 0-5000, 5001-10000 etc.. and so on.
    and then showed all 4 parameters are listbox on the selection screen.
    now the first 3 parameters are from infotype pa0001 and the last is from pa0008.
    Now I want to select pernr, persg ,persk ,plans, begda ,endda fields from infotype pa0001, and 'ansal' field from pa0008 , with the help of a dynamic where clause, is it possible, because here it might be needed for a join as well.
    Please help me out with some sample coding help.
    Regards
    Tarun

    DATA: lv_query TYPE string.
      lv_query = ' '.
      IF  position IS NOT INITIAL.
        IF lv_query IS NOT INITIAL.
          CONCATENATE lv_query '  and p1~plans eq   position '  '' INTO lv_query.
        ELSE.
          CONCATENATE  ' p1~plans eq  position '  '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  grade IS NOT INITIAL.
        IF lv_query IS NOT INITIAL .
          CONCATENATE lv_query '  and p1~PERSK eq  grade ' '' INTO lv_query.
        ELSE.
          CONCATENATE '  p1~PERSK eq  grade  ' '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  level IS NOT INITIAL.
        IF lv_query IS NOT INITIAL .
          CONCATENATE lv_query '  and p1~PERsg eq  level ' '' INTO lv_query.
        ELSE.
          CONCATENATE ' p1~PERsg eq  level  ' '' INTO lv_query.
        ENDIF.
      ENDIF.
      IF  sal_slab IS NOT INITIAL.
        SELECT pernr ansal begda endda FROM pa0008 INTO CORRESPONDING FIELDS OF TABLE lt_st_p8 WHERE ansal = sal_slab.
        *IF lv_query IS NOT INITIAL .*
          *CONCATENATE lv_query '  and p8~ansal le  sal_slab ' '' INTO lv_query.*
        *ELSE.*
          *CONCATENATE '  p8~ansal le  sal_slab  ' '' INTO lv_query.*
        *ENDIF.*
      ENDIF.
    SELECT p1~pernr
        p1~persg p1~persk p1~plans p1~begda p1~endda
         p8~ansal
      INTO CORRESPONDING FIELDS of TABLE lt_st_p1_p8
        FROM pa0001 AS p1 JOIN pa0008 AS p8  ON p1~pernr = p8~pernr
        WHERE (lv_query) .
    <Added code tags>
    Now in case of salary slab, i have ranges like 0-5000 , 5001-10000 and so on and I showed it as a listbox on sel. screen.
    So how can I read the figure after the '-'?????
    And also review, if for the previous 3 parameters it is correct, or it can be shortened and accurated.
    Edited by: Suhas Saha on Dec 28, 2011 1:44 PM

Maybe you are looking for