WHERE CLAUSE Problem

Hello all,
i think it is an old problem but i cannot find a solution.
i have the following table
CREATE TABLE XX
ID CHAR(10)NOT NULL,
other colums
the table has some rows in it, but when i do the following Select, i get no rows back:
SELECT *
FROM XX
WHERE ID >= ''
( normally the '' is replaced by a variable, but i tried it also with SQL*Plus )
Any suggestions ?
null

you'r right, but the problem is, i have to do with Oracle, DB2, SQL Server, Informix, and with ALL the other databases the empty string is NOT NULL, so you can compare it to values.
The problem is that the value is, that i have an application which is connected through ODBC resp. JDBC to different database servers, and only Oracle does the compare in that manner.
so far
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Eugenio:
The empty string '' means NULL and
NULL cannot be compared with values.
select * from dba_objects where object_name >= ''
gives "no rows selected"
If you try with ' ' (blank space) you'll have thousands of rows (in my new 8i test db 22436 ;).
Ciao<HR></BLOCKQUOTE>
null

Similar Messages

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

  • Function in where clause problem

    Hi, I use Oracle 9i release 2.
    Imagine a Query:
    select e.* from employee e
    left outer join department d
    on e.dep_id=d.dep_id
    where
    d.start_date=fn_get_start_date(some_value);
    I need all employees who works in departments which started there existance on date that is return by function.
    Now on Oracle 11 g R2 I can do this. But Oracle 9 can't do this. Why function make problems?
    Thx

    Hmm... doesn't say much ;-) I presume that's your client environment or developing tool that gives that error? It does not look like an ORA-xxxxx error?
    What happens if you do the same statement in a SQL*PLUS session? That might give a more meaningful error?
    A wild guess could be something to do with your ANSI join syntax. I have myself sometimes stumbled into bugs in version 9 when using ANSI join syntax (mostly on full outer join, though.)
    But you could perhaps try it the old-fashioned Oracle join:
    select e.*
    from employee e, department d
    where d.start_date=fn_get_start_date(some_value)
    and d.dep_id(+) = e.dep_id
    ;Oh - and now I realize that your outer join is unnecessary?
    You can just:
    select e.* from employee e
    join department d
    on e.dep_id=d.dep_id
    where
    d.start_date=fn_get_start_date(some_value);Or:
    select e.*
    from employee e, department d
    where d.start_date=fn_get_start_date(some_value)
    and d.dep_id = e.dep_id
    ;But it is a wild guess - it will only help if you happen to have stumbled upon a bug with ANSI joins.
    If that does not work, then try in SQL*PLUS to get an ORA-xxxxx error message that we can google for ;-)

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

  • Query...where clause problem in XSQL

    I am getting error with following simple example: (however it works fine when the < sign changed to greater than > sign). Anybody any idea?
    select * from emp
    where empno < 7876
    XSQL-005: XSQL page is not well-formed.
    XML parse error at line , char
    Expected name instead of .
    null

    The "less-than" sign (also known as the "left-angle-bracket") is a special character in an XML file, since it is the start of an element like <foo>.
    So, you either have to write your query like this:
    <xsql:query>
    select * from emp where empno &;lt; 7839
    </xsql:query>or like this, escaping the entire query with a CDATA section:
    <xsql:query>
    <![CDATA[
    select * from emp where empno < 7839
    ]]>
    </xsql:query>A third option is that instead of writing:
    empno < 7839
    you exploit the fact that this is equivalent to:
    7839 > empno
    and write it that way. Since "greater-than" sign does not need to be escaped specially in an XML file, it gets the job done, too.

  • Urgent: Performance problem with where clause using IN and an OR condition

    Select statement is:
    select fl.feed_line_id
    from ap_expense_feed_lines_all fl
    where ((:1 is not null and
    fl.feed_line_id in (select distinct r2.object_id
    from xxdl_pcard_wf_routing_lists r2,
         per_people_f hr2
    where upper(hr2.full_name) like upper(:1||'%')
              and hr2.person_id = r2.person_id
    and r2.fyi_list is null
              and r2.sequence_number <> 0))
    or
    (:1 is null))
    If I modify the statement to remove the "or (:1 is null))" part at the bottom of the where clause, it returns in .16 seconds. If I modify the statement to only contain the "(:1 is null))" part of the where clause, it returns in .02 seconds. With the whole statement above, it returns in 477 seconds. Anyone have any suggestions?
    Explain plan for the whole statement is:
    (1) SELECT STATEMENT CHOOSE
    Est. Rows: 10,960 Cost: 212
    FILTER
    (2) TABLE ACCESS FULL AP.AP_EXPENSE_FEED_LINES_ALL [Analyzed]
    (2) Blocks: 8,610 Est. Rows: 10,960 of 209,260 Cost: 212
    Tablespace: APD
    (6) TABLE ACCESS BY INDEX ROWID HR.PER_ALL_PEOPLE_F [Analyzed]
    (6) Blocks: 4,580 Est. Rows: 1 of 85,500 Cost: 2
    Tablespace: HRD
    (5) NESTED LOOPS
    Est. Rows: 1 Cost: 4
    (3) TABLE ACCESS FULL XXDL.XXDL_PCARD_WF_ROUTING_LISTS [Analyzed]
    (3) Blocks: 19 Est. Rows: 1 of 1,303 Cost: 2
    Tablespace: XXDLD
    (4) UNIQUE INDEX RANGE SCAN HR.PER_PEOPLE_F_PK [Analyzed]
    Est. Rows: 1 Cost: 1
    Thanks in advance,
    Peter

    Thanks for the reply, but I have already checked what you are suggesting and I am pretty sure those are not causing the problem. The hr2.full_name column has an upper index and the (4) line of the explain plan shows that index being used. In addition, that part of the query executes on its own quickly.
    Because the sql is not displayed in an indented format on this page it is a little hard to understand the structure so I am going to restate what is happening.
    My sql is:
    select a_column
    from a_table
    where ((:1 is not null) and a_column in (sub-select statement)
    or
    (:1 is null))
    The :1 bind variable is set to a varchar2 entered on the screen of an application.
    If I execute either part of the sql without the OR condition, performance is good.
    If the :1 bind variable is null with the whole sql statement (so all rows or a_table are returned), performance is still good.
    If the :1 bind variable is a not-null value with the whole sql statement, performance stinks.
    As an example:
    where (('wa' is not null) and a_column in (sub-select statement)) -- fast
    where (('wa' is null)) -- fast
    where (('' is not null) and a_column in (sub-select statement) -- fast
    or
    ('' is null))
    where (('wa' is not null) and a_column in (sub-select statement) -- slow
    or
    ('wa' is null))

  • Problem in case of or condition in  where clause in case of leftouter joi.

    hi
    i am encountering a wierd problem.
    in a select query if i have a left outer join and a or condition in where clause the order of condition in or matters and if i use a to_char problem is solved.
    see query below
    select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
    i have a single record in table custsupp with CS_FLAG ='B' the above does not return result. but if i move CS_FLAG='B' on left of or i.e
    select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (CS_FLAG='B' or CS_flag ='C') and custsupp.state = a.id
    i get the rsult.
    also if i remove left outer join and keep order of condition as it is i get result i.e
    select * from custsupp ,state a where (CS_FLAG='C' or CS_flag ='B') and custsupp.state = a.id
    also if i add a to_char to co,umns CS_FLAG i get the result.
    select * from custsupp left outer join Salesperson s on custsupp.sales_rep = s.id ,state a where (to_char(CS_FLAG)='C' or to_char(CS_flag ='B')) and custsupp.state = a.id
    why it is so?
    CS_flag is of type nchar
    Shreyas
    Edited by: shreyasd on Jun 9, 2010 11:07 PM

    First if you don't want to take credit of the free sample then follow the below procedure:
    1. Do the GRN for all the three item and for the free item in the excise tab at the item level select the material as non cenvatable. Just remember to add base value of the item
    2.  If you want to capture the Part1 entry then just do the normal transaction and while posting the excise with J1IEX just remove the excise duties for the free item.
    3. For paying the vendor the excise amount, just do subsequent debit in the MIRO and in the details tab add in the unplanned delivery cost the amount that you want to pay for the excise duties
    Second case if you want to take credit of the duties:
    1. Do the Normal GRN process, add the base value and excise values for the free item.
    2. Post the Excise duites with J1iEX.
    3. The with the account entry you can settle the excise payment
    Hope this will help you
    Enjoyyyyyyyyyyy
    Akshit

  • PL/SQL Evaluation problem of where clause in case of  NUMBER column type

    I found the following problem in Oracle® Database 2 Day Developer's Guide 11g Release 1 (11.1) B28843-04:
    The sole parameter of function eval_frequency is employee_id IN employees.employee_id%TYPE.
    An ORA-01422 exception occurs when the execution reaches the following select command
    SELECT e.hire_date
    INTO hire_date
    FROM employees e
    WHERE employee_id= e.employee_id;
    A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there were no WHERE clause at all.
    Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function and used this variable in the where clause, but I consider this "solution" as being no solution.
    It is pointless to use %TYPE parameter of a function for flexibility if I must degrade this flexibility by a fixed declaration of a temporary variable of the same type as the column in question.
    What is wrong?
    The Developer'Guide I used, the Oracle Sql Developer I used or the PL/SQL version ?

    Hi,
    Welcome to the forum!
    user8949829 wrote:
    A possible cause of the error is that the type of employee_id is NUMBER while the employees.employee_id is NUMBER(6,0) . The result of the selection is the same as there I don't think so. The variable employee_id is defined as having the exact same type as the eponymous column. Even if it didn't, I believe Oracle will always implicity convert between datatypes when possible, rounding if necessary. That may cause errors, but it isn't causing this error.
    No, the error has nothing to do with the data type. It has to do with the ambiguity of employee_id: is it a column, or is it a variable?
    The default is that it means the column name, so
    WHERE   employee_id = e.employee_idis equivalent to saying
    WHERE   e.employee_id = e.employee_idwhich isn't quite the same thing as not having a WHERE clause; rows with NULL employee_id would still be excluded, if there were any.
    I think it's best not to use variable names that are the same as column names. You could call the variable v_employee_id, or, since it's an IN-argument, in_employee_id.
    If you must use a variable that can be mistaken for a column, then qulaify it with the name of the procedure, like this:
    WHERE   eval_frequency.employee_id = e.employee_id
    Everything worked fine, when I declared a temporary variable of NUMBER(6,0) for storing the actual parameter of function That makes sens. You probably gave that variable a name that couldn't be mistaken for a column in the table.
    Edited by: Frank Kulash on Jan 12, 2011 8:27 PM

  • Problem with DECODE block in WHERE clause

    Hi,
    I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
    SELECT 'hello' FROM DUAL
    WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    I think some problem is there in my WHERE clause.
    But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
    SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    FROM DUAL;
    Please help me to get out of this problem. Thank you so much in advance.
    Thanks,
    Ramji.

    The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
    'sample1', 'sample2', 'sample3' is a single string. Consider it x.
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
    is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
    or
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
    For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
    also does'nt work.
    Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'.

  • WHERE clause in a SMARTFORM loop, problems with parenthesis

    Hi all gurus,
    a simple question: I'm coding a LOOP in the form builder for a smartform ... this simple loop should bind text elements to every position of a purchase order. The WHERE clause should be as follows:
    WHERE GUID = WA_ITEM-GUID
    AND ( TDID EQ 'ZDES' OR TDID EQ 'ZDST' ).
    Anyway, in the Form Builder I didn't find a way to add parenthesis; I workarounded the problem with the following query:
    (conditions in lines are in AND conjunction)
    GUID EQ     WA_ITEM-GUID
    TDID      EQ   'ZDES'
    OR
    GUID EQ     WA_ITEM-GUID                                                                               
    TDID      EQ 'ZDST'.
    It's quite a 'bad' way, but it works. I wonder if there's a way to express "complex" WHERE clauses (with addiction of parenthesis) in Form Builder.
    Thanks in advance

    In this case, your solution is the one that works. However in more complex cases with more variables, this can proove difficult to make or mantain.
    What I usually do is use the first part of the condition in the where and then add a condition to the printing area with the rest of the formula. Just remember to document this so that you'll find it easy and it's way more amintainable.
    In this case the loop would contain WHERE GUID = WA_ITEM-GUID and the inside condition TDID EQ 'ZDES' OR TDID EQ 'ZDST. This creates the and between the two blocks.

  • Problems with WHERE CLAUSE in selects executed by BAPIs

    Dear Experts,
    I'm trying to make a SAP Java Connector. My problem is that, when they are called by Java, BAPI functions don't run in the same manner as in SAP testing mode .
    I tested two BAPI functions called through my connector and I saw with the debbuger that BAPI functions don't execute the select and loop at with a WHERE clause when they are called by Java, therefore they throw errors. But in the SAP testing mode functions work just fine.
    I'm  new to SAP and I don't know why this happens. Would you like to explain to me how to fix this problem?
    Thank you very much.
    Kind regards,
    Maricica

    979380 wrote:
    Yeah,i m sorry.I m a forum newbie.All right,we ve been given an oracle account for the purpose of this project,an we have connect to the oracle database either via linux terminal with sqlplus,or via oracle client and plsql.So i have to create some tables,then fill these tables with tuples(we ve been given fixed .sql files to do that),and we re suggested to do that from the linux terminal.I did that successfully.Then we have to run some queries either in terminal or plsql.I chose plsql.I connect,i can see the tables that i have created but when i run(in both sql and terminal window) for example the query "select * from table_1",i take 0 rows as a result.I tested to run the query from terminal(with sqlplus) to see if the tables are really empty,but i recieve the results as i should.
    I am sorry for my chaotic writing but i cant even explain the problem to myself better and i m not a native.
    (im using oracle version 11.2.0.1, this is the first time i m using oracle databases and i m a rookie in databases in general)
    Edited by: 979380 on 1 Ιαν 2013 10:33 πμ
    [oracle@localhost ~]$ sqlplus user1/user1
    SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 1 11:19:29 2013
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table table_1 (id number);
    Table created.
    SQL> select * from table_1;
    no rows selected
    SQL> insert into table_1 values(1);
    1 row created.
    SQL> select * from table_1;
            ID
             1
    SQL> in order to SELECT any rows from any table, first you must INSERT data into the table!
    is COPY & PASTE broken for you?

  • Problem with column alias: Unknown column 'avg_rating' in 'where clause'

    Hello,
    I have a basic sql statement as follows:
    SELECT
    e.establishment_id,
    e.establishment_name,
    avg(r.rating) avg_rating
    FROM
    establishment e,
    rating r,
    comment com,
    establishment_country ec,
    country_ref cou
    where
    etc...
    and avg_rating >= 1
    and 0=0
    group by e.establishment_id
    order by e.establishment_idI have used a column alias for "avg(r.rating)" and named it "avg_rating".
    It works in my Mysql Query browser without problem but when I run it from Java I get this:
    java.sql.SQLException: Unknown column 'avg_rating' in 'where clause'
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2917)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:824)
        at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:145)
        at arcoiris.SearchSessionBean.performSearch(SearchSessionBean.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
        at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
        at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
        at org.jboss.ejb.Container.invoke(Container.java:873)
        at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
        at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
        at $Proxy172.performSearch(Unknown Source)
        at arcoiris.SearchManagedBean.performSearch(SearchManagedBean.java:171)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
        at javax.faces.component.UICommand.broadcast(UICommand.java:312)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)Can anyone help please?
    Thanks in advance,
    Julien Martin.

    I am having the similiar problem, the query in java creator IDE works fine after i upgraded the J-connector and changed DataSource type for MySQL to mysql-connector-java-5.0.4-bin.jar. but still i cannot bind any control in the form to the aliased column. this is really frustrating. can anyone from Sun Developer explain?
    THX

Maybe you are looking for