Invalid relational operator in where clause dynamic

I have a procedure where I pass the WHERE CLAUSE as a parameter like this:
PROCEDURE PRC_CONSULTAR_AFIL_PEND(PV_WHERE IN VARCHAR2,
RESULTSETM IN OUT SYS_REFCURSOR)
IS
BEGIN
OPEN RESULTSETM FOR
'SELECT PAISAFIL,
TIPDOCAFIL,
NUMDOCAFIL,
APPAFIL,
APMAFIL,
NOMAFIL,
SEXAFIL,
FECNACAFIL,
CODPNA,
ESTADO,
FECHA,
TO_DATE(FECGEN),
NOMCOLUMN
FROM SUNAFILERR
WHERE ' || PV_WHERE;
I am passing the where clause as: 'APPAFIL'||' '||'APMAFIL'||' '||'NOMAFIL LIKE UPPER(rojas%)'

Miguel Angel wrote:
I have a procedure where I pass the WHERE CLAUSE as a parameter like this:
PROCEDURE PRC_CONSULTAR_AFIL_PEND(PV_WHERE IN VARCHAR2,
RESULTSETM IN OUT SYS_REFCURSOR)
IS
BEGIN
OPEN RESULTSETM FOR
'SELECT PAISAFIL,
TIPDOCAFIL,
NUMDOCAFIL,
APPAFIL,
APMAFIL,
NOMAFIL,
SEXAFIL,
FECNACAFIL,
CODPNA,
ESTADO,
FECHA,
TO_DATE(FECGEN),
NOMCOLUMN
FROM SUNAFILERR
WHERE ' || PV_WHERE;
I am passing the where clause as: 'APPAFIL'||' '||'APMAFIL'||' '||'NOMAFIL LIKE UPPER(rojas%)'So your where clause is
WHERE APPAFIL APMAFIL NOMAFIL LIKE UPPER (rojas%)Can you see why that's an error? It would make more sense if there was an operator between APPAFIL and APMAFIL, but then there's obviously something missing between APMAFIL and NOMAFIL as well, and some quotes missing later on.
The following is valid SQL code
WHERE   APPAFIL  != APMAFIL
AND     NOMAFIL  LIKE UPPER ('rojas%')Of course, I have no idea if that's what you want or not.
Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements) for any tables used, and the results you want from that data.
if the problem involves parameters (such as the pv_where), then post a couple of different parameters, and the results you want from the same sample data for each parameter.
Explain how you get those results from that parameter and that data.
Always say which version of Oracle you're using.

Similar Messages

  • Using regexp_instr in a where clause - invalid relational operator

    Whey I try to run this query in TOAD I get an ORA-00920: invalid relational operator error. It's part of a 10g stored procedure. When I highlight it and run it it prompts me for the missing values and then the error pops up. The AND in line 4 is highlighted.
    select CRIME_CLASSIFICATION_ID, crime_type, nvl(count(CRIME_CLASSIFICATION_ID),0) as CRIMECNT
    From vaps.vw_offenses
        where  regexp_instr(valoc,to_char(location_id))
            AND ( fromdate is null or
             offense_date between to_date(fromdate, 'mm/dd/yyyy')  AND to_date(todate,'mm/dd/yyyy')
    group by crime_classification_id, crime_type

    Hi,
    Review what REGEXP_INSTR does: it returns a NUMBER.
    Your WHERE clause couldn't make any sense if you used any other kind of NUMBER expression in that place, e.g. a NUMBER literal such as 12:
    select CRIME_CLASSIFICATION_ID, crime_type, nvl(count(CRIME_CLASSIFICATION_ID),0) as CRIMECNT
    From vaps.vw_offenses
        where  12     -- This is obviously wrong
            AND ( fromdate is null or
             offense_date between to_date(fromdate, 'mm/dd/yyyy')  AND to_date(todate,'mm/dd/yyyy')
    group by crime_classification_id, crime_type
    It's not going to work any better with a function (like REGEXP_INSTR) that returns a NUMBER.
    How can you fix it?  That depends on what you want to do.  Why are you calling REGEXP_INSTR?  What is that condition checking?
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Case with where clause - ORA-00920: Invalid relational operator

    Hi All, when I try to run the query below, I get the following error...
    ORA-00920: invalid relational operator
    00920. 00000 -  "invalid relational operator"
    *Cause:   
    *Action:
    Error at Line: 16 Column: 5
    Does anyone know what's wrong with my query? thanks in advance.
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END as "MonthNo"
    ORDER BY CONCAT (year,"MonthNo") DESC

    The problem is the as "MonthNo" - you can't give an "AS" alias to an expression in a where clause.
    You have not actually given any condition, just a set of translations from period into a number.
    You also haven't said what you're trying to do.
    Perhaps you want:
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE something
    ORDER BY CONCAT (year, CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END  ) DESC

  • Invalid relational operator

    Hi,
    if I :
    create table t (a number, b number, c number);
    and then run the following query:
    delete from t where a='1' and (b, c) in (
    select b, c from t
    where a='1'
    group by b, c
    having count(*) > 1);
    -- nothing to see here
    I get the following error:
    ORA-00920: invalid relational operator
    If I remove the "-- nothing to see here" comment, the query runs fine.
    If I remove the quotes around the 1s it also runs fine, with or without the trailing comment.
    I had a look through the forum and couldn't see this listed anywhere, though I presume others have come across similar problems?
    I presume there is a simpler test case; I tried to reduce it a bit, but most of what is there seems to be needed to reproduce the error.
    Note that it doesn't have to be a comment following the query; any text at all will cause the same error.
    regards,
    William

    Having just played around a bit, if you change the subquery to just return a single column, say "b" rather than "b" and "c":
    delete from t where a='1' and b in (
    select b from t
    where a='1'
    group by b
    having count(*) > 1);
    -- nothing to see here
    Then I get error "ORA-00911: invalid character" instead.
    If I run the buffer as a script (F5) I get:
    SQL ERROR:ORA-00911: invalid character
    delete from t where a='1' and b in (
    select b from t
    where a='1'
    group by b
    having count(*) > 1);
    -- nothing to see here
    ORA-00911: invalid character
    In case that helps you locate it at all.
    Note: if I move the "group by" clause onto the where line then it runs correctly.
    regards,
    William
    Message was edited by:
    user454290

  • Requesting help-On a report Getting ora-00920 invalid relational operator.

    Hi everyone,
    I am having a report region with the following query:
    select CASE
    WHEN ISITRECENTADDENDUM(meckey_fk,code)
    THEN
    '<a href="javascript:popUp2('''
                   || 'f?p=&APP_ID.:61:&SESSION.::NO::P61_MECKEY_FK:'
                   || &P60_MECKEY.
                   || ''', 700, 700);">'
    || '<img src="#IMAGE_PREFIX#gobut.gif">'
    || '</a>'
    ELSE NULL
    END EditAddendum,
    '<a href="javascript:popURL('''
                   ||'&REPORTS_URL.keynewmec&P_1=&P60_MECNUM.'
                   || ''', 700, 700);">'
    || '<img src="#WORKSPACE_IMAGES#printer.jpg">'
    || '</a>'
    PrintMEC,
    "CODE",
    "MECKEY_FK",
    "ADDENDUM",
    "WHO_CREATED",
    "WHEN_CREATED"
    from "C_ADDENDUMS"
    where "MECKEY_FK" = v('P60_MECKEY')
    And my function returning boolean is as follows:
    create or replace FUNCTION "ISITRECENTADDENDUM"
    (meckeyi in number,
    codei in varchar2)
    return Boolean
    is
    x varchar2(1);
    begin
    select max(code) into x from c_addendums where meckey_fk = meckeyi;
    if x = codei then
    return true;
    else
    return false;
    end if;
    exception
    when others then
    return FALSE;
    end;
    But I am getting ORA-00920 invalid relational operator. Can anyone please help me out? I am not knowing where the error is. When I run the function by itself I am getting "False" returned as expected. Appreciate any advice on this.
    Rgds,
    Suma.

    Suma,
    It looks like what you are trying to do is display a link for the record with the highest value in the Code column, and nothing for the other records.
    If that is the case, you can eliminate the function and just use a SQL query like this:
    (not tested)
    select CASE
              WHEN code = Max(code) over (partition by meckey_fk)
                 THEN
                   '<a href="#">'
                   || ' '
                   || '< img class="TargetAlertIcon" src="chrome://targetalert/content/skin/internal.png"></a>'
              ELSE NULL
           END EditAddendum,
           '<a href="#">'
           || ' '
           || '< img class="TargetAlertIcon" src="chrome://targetalert/content/skin/internal.png"></a>' PrintMEC,
           "CODE", "MECKEY_FK", "ADDENDUM", "WHO_CREATED", "WHEN_CREATED"
      from "C_ADDENDUMS"
    where "MECKEY_FK" = :P60_MECKEYIs that what you're trying to do?
    Doug

  • OA Framework LOV – How to add where clause dynamically at runtime

    Hi All,
    Following is my page design:
    MainAM (This is root Application module) Package is: mycompany.oracle.apps.<product>.<project>.server
    MainPageVO (This is the View Object associated to Main AM)
    LovAM (This Application module is for LOVs) Package is: mycompany.oracle.apps.<product>.<project>.lov.server
    FileNameLovVO (This is the View Object is for "File Name" LOV. It is associated LovAM)
    I my main page is attached to the "Main AM". In the main page, I have a custom search region and in that there is a messageLovInput type of field based on "FileNameLovVO". The field name is File Name.
    Use Case:
    When a user opens the page, I determine user type. If the use is a clerk (not a superuser) then I need to restrict values in my File Name LOV by setting where clause dynamically.
    Issue1:
    ====
    In the main page controller when I do following, OA Framework is not able to access the "FileNameLovVo".
    1. Following code is from the main page's controller:
    String userId = 100;
    LovAMImpl lovAm = new LovAMImpl();
    Serializable[] lovParameters = {userId};
    Class[] lovParamTypes = { String.class };
    lovAm.invokeMethod("initLovQuery", lovParameters, lovParamTypes);
    2. In LovAMImpl class I have created following method:
    public void initLovQuery(String useId)
    FileNameLovVOImpl fileNameLovVo = getFileNameLovVO1(); // ******This returns NULL*******
    if (fileNameLovVo == null)
    MessageToken[] errTokens = { new MessageToken("OBJECT_NAME", "getFileNameLovVO1")};
    throw new OAException("AK", "FWK_TBX_OBJECT_NOT_FOUND", errTokens);
    fileNameLovVo.initQuery(userId);
    In the above code "FileNameLovVOImpl fileNameLovVo = getFileNameLovVO1();" is returning NULL.
    Please let me know what am I missing here.
    I resolved above issue with following work around:
    1. Attached "FileNameLovVO" to "MainAM"
    2. Moved initLovQuery(String useId) method to "MainAMImpl" class.
    Is that the correct way? I would prefer NOT to attach "FileNameLovVO" to "MainAM". Any suggestions?
    Issue2:
    ====
    After using above work around I tried to set WHERE clause dynamically:
    FileNameLovVO is based on following SQL query:
    SELECT DISTINCT file_name FROM <table> WHERE USER_ID like :1
    I need to pass value for USER_ID if the user is a clerk and I need to pass '%' if the user is a supper user. I'm passing value in "LovVo.initQuery(userId)" method using following code:
    public void initQuery(String userId)
    StringBuffer whereClause = new StringBuffer(1000);
    Vector parameters = new Vector(1);
    int bindCount = 0;
    setWhereClauseParams(null);
    if ((userId != null) && (!("".equals(userId.trim()))))
    parameters.addElement(servicerId);
    whereClause.append(++bindCount);
    if (bindCount > 0)
    Object[] params = new Object[bindCount];
    parameters.copyInto(params);
    setWhereClauseParams(params);
    executeQuery();
    When I select LOV at runtime in the page, it fails with following error:
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT DISTINCT file_name FROM <table> WHERE user_id LIKE :1) QRSLT WHERE (( UPPER(FILE_NAME) like :1 AND (FILE_NAME like :2 OR FILE_NAME like :3 OR FILE_NAME like :4 OR FILE_NAME like :5))) ORDER BY file_name desc
    OA Framework tries to create following statement:
    SELECT *
    FROM (SELECT DISTINCT file_name
    FROM <table>
    WHERE user_id LIKE :1) qrslt
    WHERE (( UPPER (file_name) LIKE :1
    AND ( file_name LIKE :2
    OR file_name LIKE :3
    OR file_name LIKE :4
    OR file_name LIKE :5
    ORDER BY file_name DESC
    Any help is greatly appreciated.
    Thanks for your help guys.
    Mitesh

    I have a lovinput item which has an external LOV attached to it - the VO uses the below sql query. I want to display the addresses of the customer accounts belonging to the customer name or account entered. I have a PPR event in the account number field which is calling the onAccountNumber method in my AM - the method is getting triggered when you enter the account number and the vo returns the rowcount as 3 exactly but if you click the lovinput item - it brings back all the addresses available instead bringing back addresses beloning to the account number.
    public void OnAccountNumber(String accountNumber,String partyName,
    Boolean executeQuery)
    System.out.println("Im here on account number" + accountNumber + " PartyName:" + partyName);
    AddressVOImpl Addrvo= getAddressVO1();
    Vector parameters = new Vector(2);
    StringBuffer whereClause = new StringBuffer(100);
    int clauseCount = 0;
    int bindCount = 0;
    Addrvo.setWhereClauseParams(null); // Always reset
    if ((accountNumber != null) && (!("".equals(accountNumber.trim()))))
    whereClause.append(" Account_Number = :");
    whereClause.append(++bindCount);
    parameters.addElement(accountNumber);
    clauseCount++;
    if ((partyName != null) && (!("".equals(partyName.trim()))))
    if (clauseCount >0){
    whereClause.append(" AND ");
    whereClause.append(" Party_Name like :");
    whereClause.append(++bindCount);
    parameters.addElement(partyName);
    clauseCount++;
    Addrvo.setWhereClause(whereClause.toString());
    if (bindCount >0)
    Object[] params=new Object[bindCount];
    parameters.copyInto(params);
    Addrvo.setWhereClauseParams(params);
    System.out.println("AddressVO:" + Addrvo.getQuery() );
    //Addrvo.executeQuery();
    System.out.println("Addr Cnt:" + Addrvo.getRowCount());
    SQL used in VO
    =========
    SELECT hl.address1
    || ' '
    || hl.address2
    || ' '
    || hl.address3
    || ' '
    || hl.city
    || ' '
    || hl.postal_code
    || ' '
    || hl.state
    || ' '
    || hl.country address,
    hca.account_number,hp.party_name
    FROM hz_cust_accounts hca,
    hz_cust_site_uses_all hcsu,
    hz_cust_acct_sites_all hcs,
    hz_party_sites hps,
    hz_locations hl,
    hz_parties hp
    WHERE hcsu.cust_acct_site_id = hcs.cust_acct_site_id
    AND hcs.party_site_id = hps.party_site_id
    AND hps.location_id = hl.location_id
    AND hca.cust_account_id = hcs.cust_account_id
    AND hcsu.site_use_code = 'SHIP_TO'
    AND hcsu.status = 'A'
    AND hp.party_id = hps.party_id
    AND hp.party_id = hca.party_id
    -- AND account_number=6028
    Can someone please tell me how to restrict the addresses lov to an entered account number or customer name??

  • Error: ORA-00920: invalid relational operator (WWV-16016)

    Hi,
    When I try to query in the form, I'm getting the following error
    An unexpected error occurred: ORA-00920: invalid relational operator (WWV-16016).
    The form has a field of type varchar2 with lov attached to it. This error is happening only if I enter characters more than 40 or select a value which has more than 40 characters from the lov.
    Anbody had this problem?..Is there a solution for this?..Help would be appreciated.
    Thanks
    PJ

    I figured out the problem and it seems like if the value has any 'IN' or 'BETWEEN' and try to query this error is happening and it's not because of character length. I think Portal assumes that relational operator is entered and tries to query based on those words. Is it a bug in the Portal?..
    Thanks
    PJ

  • Invalid relational operator error

    Dear All,
    When i try to run the below query i am getting Invlid relational operator. Please help me on the below issue
    Declare
    lv_number VARCHAR2(2000);
    lv_count NUMBER;
    BEGIN
    For I IN (select emp_no from emp where rownum < 2) Loop
    lv_number := ',' ||i.emp_no||lv_number;
    ENd Loop;
    dbms_output.put_line(substr(lv_number,2));
    lv_number := ' IN ( '|| substr(lv_number,2)|| ')';
    dbms_output.put_line(lv_number);
    select Count(1)
    INTO lv_count
    FROM emp
    where emp_no|| lv_number ;
    -- The above logic written to achive my requirement
    END ;

    You need to use dynamic SQL:
    Declare
        lv_number VARCHAR2(2000);
        lv_count NUMBER;
    BEGIN
        For I IN (select empno from emp where rownum < 2) Loop
          lv_number := ',' ||i.empno||lv_number;
        ENd Loop;
        dbms_output.put_line(substr(lv_number,2));
        lv_number := ' IN ( '|| substr(lv_number,2)|| ')';
        dbms_output.put_line(lv_number);
        EXECUTE IMMEDIATE 'select  Count(1)
          FROM emp
          where empno' || lv_number
          INTO  lv_count;
        dbms_output.put_line('COUNT = ' || lv_count);
    END;
    7369
    IN ( 7369)
    COUNT = 1
    PL/SQL procedure successfully completed.
    SQL> SY.

  • AND and OR operations in WHERE clause

    Hello, Dear Oracle professionals.
    In WHERE clause when I use AND or OR operations, is there any way of working ORACLE server to select rows?
    For example
    WHERE con1 and con2 and con3 and con4 and con5OR
    WHERE con1 or con2 or con3 or con4 or con5How oracle checks this conditions ? From the begining to the end ? in order ?
    May be I should put some more probable TRUE condition to the end(or to the begin).
    Whant to know how oracle thinks.
    Thanks in advance.

    Hi,
    Khayyam wrote:
    Hello, Dear Oracle professionals.
    In WHERE clause when I use AND or OR operations, is there any way of working ORACLE server to select rows?
    For example
    WHERE con1 and con2 and con3 and con4 and con5OR
    WHERE con1 or con2 or con3 or con4 or con5How oracle checks this conditions ? From the begining to the end ? in order ?It evalauates the one that is likely to make the most difference first. In the case of AND, that means the condition that is least likely to be true (as far as the optimizer can predict).
    May be I should put some more probable TRUE condition to the end(or to the begin).It doesn't matter to the optimizer. Do whatever you find easier to read and debug.
    In ancient times, using the rule-based optimizer, order did matter, but there's no reason to be using the rule-based optimizer now. Oracle 11 doesn't even have the option.
    By the way, be careful not to mix AND and OR without parentheses. That is, never say:
    WHERE  x AND y OR z    -- ***** No!  Wrong!  ******Instead say
    WHERE  (x AND y) OR z   or
    WHERE  x AND (y OR z)   depending on what you want. If you don't use partentheses, then there are rules about how the expresssion is evaluated, but it's a waste of your time to learn them.

  • "Invalid Column" on multiple where clauses with subqueries and cfqueryparam

    I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for .  I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
    For example on the following I get "Invalid column name 'position_id'"
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND     position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND     staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
    If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
    If I only have one where clause, it works.  (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
    If I remove the where clause from my subquery (WHERE     item_id = department_staff_tbl.staff_id) it works.
    It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = #arguments.deptid#
    AND     position_id   = #arguments.posid#
    AND     staff_id      = #arguments.staffid#
    Any thoughts?

    I see two tables. So can the server. So, use qualified column-names.
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmarked_items_tbl.bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    bookmarked_items_tbl.item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_staff_tbl.department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">

  • Dynamically set ViewObject where clause dynamically from Java bean

    I have a requirement to display all of the records from a table when the JSP is first brought up, so my View Object looks like this:
    "select emp_name from emp"
    Then the users wants to ability to pass paramters to that View Object to refine the list so from by Java class I tried to do this:
    ViewObject vo = cpd.findViewObject("EmpViewObject");
    vo.setWhereClause("empName = :1");
    vo.setWhereClauseParam(1,varEmpName);
    vo.executeQuery();
    But I am getting JBO errors and I'm not sure what I'm doing wrong. Can anyone offer a hint as to how I can do this?

    this is exactly how the code is done -
    1. emp_name in the View Object
    2. emp_name in the where clause
    The two are identical. I have tried many variations of this - any time I set the where clause from my bean I get an error.
    When I take the SQL stmnt and run it in TOAD it returns expected rows when I run it in the SQL worksheet in JDev it gives an invalid Identifier - but if I hard code the where clause in the View Object it returns the same results as TOAD.

  • Adding filter conditions dynamically in WHERE clause -dynamic SQL help

    Here I have a simple condition but very complicated query. Basically, I have to put a filter condition in my where clause. "Location" comes to the stored procedure as parameter. Plus there are other parameters as well.
    If location = "all", I can run the query simply and get the result. But when Location = "CA", which is just a subset of "ALL" then I am having hard time putting one -- AND statement in WHERE clause.
    This query is designed for location = 'ALL'
    open cv for
    'Select col1, col2, col3, Col4
    from t1, t2, t3
    WHERE condition1
    AND condition2
    AND condition3'
    AND location = location_id --- This should only run if location IS NOT ALL
    I have written a dynamic query but it doesn't work for that part. Any ideas will be appreciated. Thanks,

    From what I understood
    If location = 'ALL' then
    fetch all the records
    Else
    add extra filter location_id = <supplied location id>
    End If
    If this is the condition the following logic should solve your issue.
    open cv for
    'Select col1, col2, col3, Col4
    from t1, t2, t3
    WHERE condition1
    AND condition2
    AND condition3'
    AND ((location_id = location_id and location = 'ALL') or (location_id = location))Regards
    Raj

  • How to use string operation in where clause of select query

    Hello All,
    I just want to know how can i write a restriction in select query saying retrive data only begins with name "DE*".
    Explaination: If my table has records and names starts with character then i want to write a query to fetch all the records in which names starts with DE*.
    Thanks in advance for your quick reply...
    Dev.

    Hi
    In the where clause you need to write like
    WHERE NAME LIKE 'DE%'
    Regards
    Sudheer

  • IN operator in Where Clause

    Hi Experts,
    I have been facing a problem in passing multiple values to the where clause in select query. I have 15 values in which i need to check in where condition.
    Ex:  SELECT AMATNR ASPART
               INTO TABLE IT_DIVISION
               FROM MARA AS A
               INNER JOIN MARC AS B ON
               AMATNR = BMATNR
               FOR ALL ENTRIES IN IT_UPDATE
               WHERE A~MATNR EQ IT_UPDATE-MATNR
               AND A~MTART IN ('ZLHA', 'ZFER', 'ZHAL', 'ZNLA', 'ZOPS',
                               'ZPSE', 'ZROH', 'ZUNB', 'ZVER ', 'ZDIA').
    Now i need to include some more (5) values, but its showing some error.
    Please guide me in this.
    Thnx in Adv..Meher

    Hi,
    Make use of a range table.
    types : begin of T_range,
    sign type TVARV_SIGN,
    option type TVARV_OPTI,
    low type mtart,
    high type mtart,
    end of t_range.
    data: IT_RANGE type standard table of T_range.
    data : wa_range type T_RANGe.
    wa_range-sign = 'I'.
    wa_range-option = 'EQ'.
    wa_range-low = 'ZLHA'
    append wa_range to IT_RANGE.
    wa_range-sign = 'I'.
    wa_range-option = 'EQ'.
    wa_range-low = 'ZFER'
    append wa_range to IT_RANGE.
    wa_range-sign = 'I'.
    wa_range-option = 'EQ'.
    wa_range-low = 'ZHAL'
    append wa_range to IT_RANGE.
    and so on till all your values are filled in the table and then use this table in the IN clause.
    SELECT AMATNR ASPART
    INTO TABLE IT_DIVISION
    FROM MARA AS A
    INNER JOIN MARC AS B ON
    AMATNR = BMATNR
    FOR ALL ENTRIES IN IT_UPDATE
    WHERE A~MATNR EQ IT_UPDATE-MATNR
    AND A~MTART IN it_range.
    The error which you are getting is because of the spacing between the different MTART values which you have included in the bracket.
    After every comma there should be a space.
    But you should always use range for such requirements.
    regards,
    Ankur Parab
    Edited by: Ankur Parab on Jun 23, 2009 6:59 PM

  • Conditional operator in where clause?

    I have 4 assignable parameters for filtering records. If a parameter is not assigned the filter is ignored. This is working fine with the SQL-statement below except for one scenario: if none of the parameters are assigned I get no records at all but then I need all of the records.
    with t as
        select 1 as val, 'a' as var from dual union all
        select 2 as val, 'a' as var from dual union all
        select 3 as val, 'b' as var from dual union all
        select 4 as val, 'b' as var from dual union all
        select 5 as val, 'b' as var from dual union all
        select 6 as val, 'c' as var from dual union all
        select 7 as val, 'd' as var from dual union all
        select 8 as val, 'e' as var from dual union all
        select 9 as val, 'e' as var from dual union all
        select 0 as val, 'f' as var from dual
    select *
    from t
    where t.var = decode(:pvar1,'',null,:pvar1)
    or t.var = decode(:pvar2,'',null,:pvar2)
    or t.var = decode(:pvar3,'',null,:pvar3)
    or t.var = decode(:pvar4,'',null,:pvar4)

    You need no "OR"s
    <br>
    SQL> var pvar1 char
    SQL> var pvar2 char
    SQL> var pvar3 char
    SQL> var pvar4 char
    SQL> with t as(    select 1 as val, 'a' as var from dual union all
      2      select 2 as val, 'a' as var from dual union all
      3      select 3 as val, 'b' as var from dual union all
      4      select 4 as val, 'b' as var from dual union all
      5      select 5 as val, 'b' as var from dual union all
      6      select 6 as val, 'c' as var from dual union all
      7      select 7 as val, 'd' as var from dual union all
      8      select 8 as val, 'e' as var from dual union all
      9      select 9 as val, 'e' as var from dual union all
    10      select 0 as val, 'f' as var from dual)
    11  select *from t
    12  where t.var = coalesce(:pvar1,:pvar2,:pvar3,:pvar4,t.var);
           VAL V
             1 a
             2 a
             3 b
             4 b
             5 b
             6 c
             7 d
             8 e
             9 e
             0 f
    10 rows selected.
    SQL> exec :pvar4 := 'b';
    PL/SQL procedure successfully completed.
    SQL>  with t as(    select 1 as val, 'a' as var from dual union all
      2       select 2 as val, 'a' as var from dual union all
      3       select 3 as val, 'b' as var from dual union all
      4       select 4 as val, 'b' as var from dual union all
      5       select 5 as val, 'b' as var from dual union all
      6       select 6 as val, 'c' as var from dual union all
      7       select 7 as val, 'd' as var from dual union all
      8       select 8 as val, 'e' as var from dual union all
      9       select 9 as val, 'e' as var from dual union all
    10       select 0 as val, 'f' as var from dual)
    11   select *from t
    12   where t.var = coalesce(:pvar1,:pvar2,:pvar3,:pvar4,t.var);
           VAL V
             3 b
             4 b
             5 b
    Message was edited by:
            jeneesh
    I did mistake. Follow Dave's post                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • 1080i/25p to film out

    hello. we're shooting with the HVX200 a feature film and the final will be a Film out (35 mm). we will be using final cut studio for editing. question is: when using the 1080i/25p mode (shooting progressive - recording interlace), how does the final

  • Download Saved Report in IR 4.1

    Hi, I have a query regarding saved reports feature in Interactive reports 4.1 I saved a normal report by adding some control breaks etc and make it more readable. I then saved it. Now if I want to download my saved report - I can't. It always downloa

  • Put database result set into a vector?

    I have a resultset rs I would like to put into a vector but I don't seem to get something fundamental. I can put individual items in with add() for instance but how do I dump a whole result set in there... and if I do so should I turn them all to str

  • HTTPS Tunneling in OC4J

    Has anyone got HTTPS tunneling working in OC4J when there is a "HTTP 1.1 proxy server" (to get through firewall) that requires Basic authentication between the client and OC4J? I can get this working fine with HTTP, but I need HTTPS. I'm using oc4j v

  • IPhoto missing photo's. rebuild already done

    After the recent update of iphoto 9.3.1. I can't work on some photo's anymore. They do appear in the library as thumbnail but if you click on it an exclamation point in a triangle appears. Rebuild the library but the problem remains. It concerns phot