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

Similar Messages

  • Include dynamic conditions in the where clause

    Hi All,
    I have an requirement where i need to dynamically include the conditions in the where clause based on the bind variable.
    My condition is like this.
    SELECT f.scheduled_date, a.bld_id, a.room_id, a.cage_id, f.test_num
    FROM feeding_test_results f,
    v_onl_gf_anmls a
    WHERE f.sak_feeding_test_res > 5000000
    AND f.anml_id(+) = a.anml_id
    AND f.bld_id = 'A5'
    AND f.room_id > 0
    AND f.cage_id > '0'
    case when :check_value = 1 Then
    AND scheduled_date <= '16-Apr-2009'
    AND scheduled_date >= '06-Apr-2009'
    Else
    AND scheduled_date = '16-Apr-2009'
    End
    AND f.feeding_status <> 'X') f
    Kindly anyone help me how to acheive this.
    Thanks & Regards,
    P. Gayathri Devi

    michaels2 wrote:
    and scheduled_date <= case when :check_value = 1 then date '2009-04-16' end
    and scheduled_date >= case when :check_value = 1 then date '2009-04-06' end
    and scheduled_date = case when not :check_value = 1 then date '2009-04-16' end
    Hmmm, you may want some NVL's around those case statements such as..
           and scheduled_date <= NVL(case when :check_value = 1 then date '2009-04-16' end,scheduled_date)
           and scheduled_date >= NVL(case when :check_value = 1 then date '2009-04-06' end,scheduled_date)
           and scheduled_date = NVL(case when not :check_value = 1 then date '2009-04-16' end,,scheduled_date)or some such thing. Otherwise the comparisons with Null will just cause it all to fail.

  • Issue with dynamically setting where clause in OAF

    Hi All,
    I have a View object having the query below:
    SELECT  rownum LINENUM,
            B.line_id LINE_ID,
            B.INVENTORY_ITEM_ID INVITMID ,
            B.QUANTITY_DELIVERED PICKQTY         
    from   MTL_TXN_REQUEST_HEADERS A,
            MTL_TXN_REQUEST_LINES  B
      WHERE A.HEADER_ID=B.HEADER_ID
       AND A.MOVE_ORDER_TYPE=2 
       AND 'on'=:1
       AND B.TO_SUBINVENTORY_CODE=NVL(:4,B.TO_SUBINVENTORY_CODE)
       AND A.request_number=NVL(:5,A.REQUEST_NUMBER) 
    UNION ALL
    SELECT  rownum LINENUM,
            a.wip_entity_id LINE_ID,
            a.INVENTORY_ITEM_ID INVITMID,
            a.QUANTITY_ISSUED PICKQTY      
      FROM  WIP_REQUIREMENT_OPERATIONS a,
            eam_work_orders_v b
      WHERE a.wip_entity_id=b.wip_entity_id
         AND 'on'=:2
        AND a.ATTRIBUTE2=NVL(:4,a.ATTRIBUTE2)
      and b.wip_entity_name=NVL(:6,b.wip_entity_name)
    I need to pass dynamically a condition to my where clause that i can handle it by defining two bind parameters in the vo query and can pass it but the problem is the bind variable contains a string like 1311,13112,14445 that i need to pass for a field such as B.line_id in the first query and b.wip_entity_id in the second query so when i am trying by passing the string as one value it is working fine but for value separetd by comma it is giving prob.
    so i tried by passing dynamic where clause but it is everytime executing for first clause only how i can pass dynamically both the queries.
    vo.setWhereClause("LINE_ID in "+wherclause);
    please help me out
    Thnaks
    Deb

    Hi Gaurav,
    Thnaks for the reply i tried belwo way u suggested but the query is executing multiple times and i am not getting the correct data as expected.
    public void processPOData (String wherclause)
                 OAViewObject vo = this.getXXDPECONTAINLINESVO1();
                    String query =vo.getQuery();
                    String newwhereclause ="LINE_ID = "+wherclause;
                    StringBuffer stringbuffer = new StringBuffer();  
                stringbuffer.append("SELECT * FROM (");
                stringbuffer.append(query);
                stringbuffer.append(") where ");
                stringbuffer.append(newwhereclause);          
        ViewDefImpl viewdefimpl = getXXDPECONTAINLINESVO1().getViewDefinition();
                viewdefimpl.setQuery(stringbuffer.toString());
                 vo.reset();
                 vo.clearCache();
                vo.executeQuery();
                    System.out.println("where clause:"+wherclause);
    in my log file the query is forming like below:
    SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM ( SELECT * FROM ( SELECT  rownum LINENUM,
            B.line_id LINE_ID,
            B.INVENTORY_ITEM_ID INVITMID ,
            B.QUANTITY_DELIVERED PICKQTY ,
            B.TO_SUBINVENTORY_CODE UNLOADINGPNT,
            A.REQUEST_NUMBER RRNUM,
            NULL WORKORDNUM,
            NULL DTRNUM,
            A.description,
            A.FROM_SUBINVENTORY_CODE FROM_SUB,
            A.TO_SUBINVENTORY_CODE  TO_SUB,
            NULL SOURCE       
    from   MTL_TXN_REQUEST_HEADERS A,
            MTL_TXN_REQUEST_LINES  B
      WHERE A.HEADER_ID=B.HEADER_ID
       AND A.MOVE_ORDER_TYPE=2  
    UNION ALL
    SELECT  rownum LINENUM,
            a.wip_entity_id LINE_ID,
            a.INVENTORY_ITEM_ID INVITMID,
            a.QUANTITY_ISSUED PICKQTY,
            a.ATTRIBUTE2 UNLOADINGPNT,
            NULL RRNUM,
            b.WIP_ENTITY_NAME WORKORDNUM,
            NULL DTRNUM,
            b.description,
            NULL FROM_SUB,
            NULL TO_SUB,      
            b.source SOURCE
      FROM  WIP_REQUIREMENT_OPERATIONS a,
            eam_work_orders_v b
      WHERE a.wip_entity_id=b.wip_entity_id ) )) where LINE_ID = 30026) where LINE_ID = 30026) where LINE_ID = 30026
    But in my page i am getting all the data instead of only for line 30026, please help me out

  • Dynamic XQuery Where clause

    I have the following schema:
    <?xml version="1.0"?>
    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="CountryRiskService"
    targetNamespace="CountryRiskService"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    <xs:element name="CountryRiskParameters">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="countryId" type="xs:int" minOccurs="1" maxOccurs="unbounded"/>
    <xs:element name="catA" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    I am passing this into my Logical Data Service, what I want to do is create a dynamic XQuery where clause if the catA field is populated, ignore it if it isn’t, so basically, I want to be able to create a dynamic query based on the parameters requested, so I have the following XQUERY:
    declare function tns:getCountries($countryRiskInput as element(ns7:CountryRiskParameters)) as element(ns0:CountryRiskInfo)* {
    for $tbl_high_risk_countries in ns1:tbl_high_risk_countries()
    where $countryRiskInput/ns4:countryId = $tbl_high_risk_countries/country_id
    where $countryRiskInput/ns4:catA = $tbl_high_risk_countries/risk_catA
    I really thought that DSP would be able to handle this on the fly since the element is optional but if I don’t populate it, I get nothing back, the idea is I want to increase the number of elements in my schema so my consumers have the ability to filter the results they want, so above, I don’t want the second where clause if catA isn't specified, any ideas how to accomplish this?

    Simply add the disjunction of the input being empty.
    for $tbl_high_risk_countries in ns1:tbl_high_risk_countries()
    where $countryRiskInput/ns4:countryId = $tbl_high_risk_countries/country_id
    where ( $countryRiskInput/ns4:catA = $tbl_high_risk_countries/risk_catA or empty( $countryRiskInput/ns4:catA )
    But suppose you have 27 different elements that you might want to filter on - the xquery gets long and ugly. You might want to looking into using FilterXQuery. Visit http://edocs.bea.com/aldsp/docs25/, search on FilterXQuery, look for the tutorial.
    If your queries get more complicated, you would do well to look into generating ad hoc queries. (edocs as well).

  • Need help in clearing string buffer during dynamic VO where clause in oaf

    Hi All,
    I am dynamically setting where clause in OAF using string buffer, but the issue is when i am executing the vo multiple times so the old data in the string buffer it is not clearing .so every time my where clause adding to the query and it is erroring out, please help me how to clear string buffer class in oaf.
    Thnaks

    Hi,
    Could you please share the code segment for reference. Then we can tell the solution.
    Regards,
    Tarun

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

  • Function-based Index and an OR-condition in the WHERE-clause

    We have some problems with functin-based indexes and
    the or-condition in a where-clause.
    (We use oracle 8i (8.1.7))
    create table TPERSON(ID number(10),NAME varchar2(20),...);
    create index I_NORMAL_TPERSON_NAME on TPERSON(NAME);
    create index I_FUNCTION_TPERSON_NAME on TPERSON(UPPER(NAME));
    The following two statements run very fast on a large table
    and the execution-plan asure the usage of the indexes
    (-while the session is appropriate configured and the table is analyzed):
    1)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%';
    2)     select count(ID) from TPERSON where NAME like 'Mil%' or (3=5);
    In particular we see that a normal index is used while the where-clause contains
    an OR-CONDITION.
    But if we try the similarly select-statement
    3)     select count(ID) FROM TPERSON where upper(NAME) like 'MIL%' or (3=5);
    the CBO will not use the function-index.
    (This behavior we only expect with views but not with indexes.)
    We ask for an advice like an hint, which enable the CBO-usage
    of function-based indexes in connection with OR.
    This problem seems to be artificial because it contains this dummy logic:
         or (3=5).
    This steams from an prepared statement, where this kind of boolean
    flag reduce the amount of different select-statements needed for
    covering the hole business-logic, while using bind-variables for the
    concrete query-parameters.
    A more realistic (still boild down) version of our prepared select-statement run in
    SQL Plus:
    define x_name = 'MIL%';
    define x_firstname = '';
    select * FROM TPERSON
    where (upper(NAME) like '&x_name' or ( '&x_name' = ''))
    and (upper(FIRSTNAME) like '&x_firstname' or ('&x_firstname' = ''))
    and ...;
    In particular we dont refernce the tablecolumn , but the QUERY-Parameter
    yield the second boolean value in the or-condition.
    The problem is that this condition ('&x_name' = '') dont use any index.
    thanks a lot for spending your time with this problem

    Try
    SELECT /*+ RULE */
    as your hint. I don't have the book with me, but this last weekend I read a section about your very problem. The book was a Oracle Press gold cover about Oracle 8i Performance tuning. If you e-mail me I can quote you the chapter when I get home Friday.

  • Like condition in the where clause.

    Dear All,
    I have created a new form using a datablock wizard with one table.
    Now i placed a text box and a button in the same form. I will be entering the value in the text box and based up the condition in the where clause of the datablock property i am restricting the values where the column name is thetext box value.
    Now my problem is i need to give a string value in the text box and the datablokc has to populate based up the like condtion. I dont know the syntax how to give like condition in the where clause of the property pallet.
    Please help me in this.
    Thanks in advance.
    Cheers,
    Raju

    Maybe try this ...
    Create a button to query the block :
    In the WHEN-BUTTON-PRESSED-Trigger enter :
    DECLARE
        v_block_def_where         VARCHAR2(255)     := '1 = 1';
    BEGIN
        v_block_def_where := v_block_def_where || ' AND NAME_OF_YOUR_TABLE_COLUMN LIKE ''' || '%' || :NAME_OF_YOUR_BLOCK.SEARCH_ITEM || '%' ||  '''';
        SET_BLOCK_PROPERTY('NAME_OF_YOUR_BLOCK', DEFAULT_WHERE, v_block_def_where);
        GO_BLOCK('NAME_OF_YOUR_BLOCK');
        EXECUTE_QUERY;
    END;

  • Dynamically adding filters in where clause in sql server

    Hello I have a question, 
    may be asked many times but could not find a thread,
    I have 8 parameters,... and user can select any of these parameters they can select 3,4 or all 8.
    I know we could use dynamic sql for this, because the sql is same.. just the where clause changes as how many parameters we are selecting, 
    i am using sql server 2012.. is there a easy way to manage this,
    Please let me know.

    Consider static (dynamic) search:
    http://www.sommarskog.se/dyn-search.html
    Alternative, dynamic SQL:
    http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • Dynamic Query Where Clause

    Hi,
    I have the following query in a SQL Query (Pl/Sql Function Body Returning Sql Query) report:
    DECLARE
    q VARCHAR2(32767); -- query
    w VARCHAR2(4000) ; -- where clause
    we VARCHAR2(1) := 'N'; -- identifies if where clause exists
    BEGIN
    q:= 'SELECT "OSP_ID",' ||
    ' "OSP_NUMBER",'||
    ' "PROPOSAL_TITLE",'||
    ' "PROPOSAL_TYPE",'||
    ' "AGENCY_TYPE_CODE",'||
    ' "AGENCY_TYPE",'||
    ' "AGENCY_CODE",'||
    ' "AGENCY_NAME",'||
    ' "AGENCY_ABBREVIATION",'||
    ' "SPONSOR_CODE",'||
    ' "SPONSOR_NAME",'||
    ' "PI_NAME",'||
    ' "PI_EMP_NUMBER",'||
    ' "PI_PERS_ID" '||
    ' FROM "PROPOSAL_V" ';
    IF :P25_OSP_NUMBER != '-All-'
    THEN
    w := ' OSP_NUMBER = :P25_OSP_NUMBER ';
    we := 'Y';
    END IF;
    IF :P25_PROPOSAL_TYPE != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    ELSE
    w := ' PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    we := 'Y';
    END IF;
    END IF;
    IF we = 'Y'
    THEN q := q || ' WHERE '|| w;
    END IF;
    RETURN q;
    END;
    What I need is to change the ' OSP_NUMBER = :P25_OSP_NUMBER ';
    to ' OSP_NUMBER LIKE '%'||:P25_OSP_NUMBER'%'|| ';
    But I'm getting errors when I do like above.
    Can somebody please help...
    Thanks in advance
    - Pradeep

    First of all, get rid of that silly "where exists" variable, just add a where clause like where 1=1 to the query and keep adding dynamic clauses with AND clause as needed.
    Try
    q := q||'and OSP_NUMBER LIKE ''%'''||:P25_OSP_NUMBER||'''%''';

  • How to dynamically build where clause in Linq

    Hello everyone,
    Oracle DB:11gR2
    Oracle Client: 11.2.0.3.0 (ODP.NET)
    Oracle Developer Tools for Visual Studio
    VS 2010 (C#)
    In a Windows Form, we need to query the data based on the values of dropdown listboxes, which user will select.
    Let's say, two combox, one is for Department and one is for Salary
    Department:
    -1 All
    10 Department 1
    20 Department 2
    30 Department 3
    Salary:
    -1 All
    1 < 20000
    2 20000 to 50000
    3 50000 to 100000
    4 > 100000
    Here is C# code to query data:
    using (var myEDMctx = new HREntities())
    var LINQrslt = from emp in myEDMctx.EMPLOYEES
    select emp;
    The default values for both combox should be All.
    How to write the dynamic where clause for this LINQ?
    Thanks in advance!!!

    There is nothing Oracle-specific about dynamic LINQ queries. Dynamic LINQ queries are handled all the same way, no matter which data source you use. Microsoft describes how to use Dynamic LINQ here:
    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
    http://weblogs.asp.net/davidfowler/archive/2010/08/19/dynamic-linq-part-2-evolution.aspx

  • Dynamically setting where clause parameter before the page load

    Hi Experts,
    I do have the following requirement.
    I am working on jsf page in ADF10.1.3.3. I have a View Object which displays the results on the screen. Can someone provide me some example where I can dynamically set the where clause parameter to my Query in VO before the Page Load happens(By Overriding the Prepare Model) and display results on screen.
    Thanks

    Hi,
    Thanks for yor advice.
    I need to write the method in Prepare Model method when the page loads and not in AM.
    Here in the page there is no action as such.
    On the Page load we need to directly set the Where Clause on the VO.
    Provide me some examples if any.
    Thanks

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

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

  • How to use multiple search conditions in the where clause

    Hi,
    Below is my query
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctacct,sum(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
      CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
    This one gives me the exact result i want, now if i add one more to my where clause like this
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctacct,sum(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
      CTACCT like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%' or
      CTACCT like '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
    This query doesnt give me the exact values instead it gives me all the weird values.Can someone please help me with how to work on this where clause?
    Thanks

    Hi Patrick,
    This is what i ve tried earlier and it isnt working .If i use the first query
    /****** Script for SelectTopNRows command from SSMS  ******/
    SELECT distinct 
    ctdesc,SUM(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
     CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
       --OR
       --CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
      and GLYEAR = 2014
      and CTDESC = 'Sales'
      group by ctdesc
    The result set is 
    Sales                        
    -182273.96
    And if i use the second query
    SELECT distinct 
    ctdesc,SUM(GLMN02)
    --,ctdesc,CTPAGE
    --SUM(GLMN02)
      FROM [ODS].[Staging].[tODS_INF_GLPCT]
      inner join 
      [ODS].[Staging].[tODS_INF_GLPGL] ON tODS_INF_GLPCT.CTPAGE = tODS_INF_GLPGL.GLPAGE
      where 
     CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4110%'
     OR
       CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
      and GLYEAR = 2014
      and CTDESC = 'Sales'
      group by ctdesc
    The result set i get is 
    Sales                        
    -1455441.08
    And i verified that  CTAcct LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9]-63020-4115%'
    this second line of where clause has not desc as Sales.
    I am not sure whats causing the difference in the values.
    Can you please help me with this?
    Thanks

Maybe you are looking for

  • Airport express Blinks Yellow After Setup

    I'm sure this has been asked before, but I couldn't find the answer. I'm running windows xp on my desktop and have a DLink wireless router. I'm trying to use airport express to stream music to my stereo. I've had it up and running in the past, but my

  • Credit Management- FD32

    Can anyone pls tell me, how the value against the field "Sales value" is getting calculated/reflected in FD32 , for a particular customer? For a particular customer, there are NO open SOs ( in VA05),but still some value is reflected in FD32. Request

  • Committed quantity query

    Does anyone have a query that can detail the commited quantity in the Item Master Detail Inventory Data Detail tab? Thanks, Jeff

  • Xcelsius and Reporting Services issue

    Hi, I'm having problems with the integration of xcelsius and Reporting Services. i need to install in the server the XRS (xcelsius Reporting Services) correct? I also need to change the Web.config to tell the XRS the location of the reports? After th

  • ORA-01033 and flash back database

    I don't really know how the flashback database work. I enabled the backup recovery option during the 11g R2 installation. It will automatic scheduled the backup around 2:00AM daily. My question is does it automatically restart the database after the