Conditional where clauses in database adapter

I am trying to write a query in a database adapter that allows for conditional where clauses. Specifically, I want to include or not include a where clause (and clause) if an input variable is empty or not. Can a prepared statement with lexical parameters be used in a database adapter? Or is there another way to do this?
Thanks in advance.

I am afraid that you can only bind parameters to the SQL, you can't bind the SQL itself to the SQL. We do have QueryByExample support, where based on what fields are set in an example object, it will construct a different SQL select.
If you pass in
<Address>
<street/>
<city>
<state>CA</state>
</Address>
it will return all addresses in California. If you pass in:
<Address>
<street/>
<city>Los Angeles</city>
<state/>
</Address>
it will return all addresses in Los Angeles.
Thanks
Steve

Similar Messages

  • Dynamic where clause in Database Adapter, or workaround?

    Hello friends,
    Is there any way to change where clause in Database Adapter (DA) dynamically.
    For e.g. i do have Database Adapter with sql statement: select col1,col2 from my_table. Originally i have many parameters which are not mandatory so instead of creating where clause in DA like:
    select col1, col2 from my_table where+
    *((#p_col_1 is not null and #p_col_1=col1) or #p_col_1 is null)*
    and ...
    and  ((#p_col_n is not null and #p_col_n=col_n) or #p_col_n is null)
    i would like to create a where clause dynamically depend on what parameters are not empty or receive where clause as parameter. Is it possible? Are there any others workarounds you can suggest?
    will appreciate any thoughts...

    Thanks Deepa for the links, their where quite helpful. And i must admit this partially answers my question (at least example i provided).
    However - how about if i'd like to use LIKE clauses instead of =, or IN or NOT IN? e.g:
    select col1, col2 from my_table where+
    ((#p_col_1 is not null and #p_col_1 LIKE col1) or #p_col_1 is null)
    and ...
    and ((#p_col_n is not null and col_n IN #p_col_n) or #p_col_n is null)
    Is it possible?
    thanks in advance

  • Dynamic where clause in database adapter

    Hi
    I have requirement to develop SOA service for search page! The back-end query for search is required to have where clauses to be appended to SELECT statement dynamically depending upon search criteria the user selects!
    E.g. if user is searching employee from a portal! If employee selects mobile number of the employee, or joining date range or other criteria, then accordingly appropriate clauses are to be appended to SEARCH SELECT statement.
    Can we achieve same while implementing executing database query through database adapter from BPEL service?
    Thanks In Advance
    Priyadarshi 

    It is difficult using the standard database adapter approach. You may have to use nested sql queries.Following is a good example of the same.
    Neeraj Sehgal - Experimenting with SOA: Pass multiple parameters, dynamic query in Pure SQL in Database Adapter
    If your only problem in using this that you are hard coding the connection details  , you can use the datasource jndi name in the query. hence you will not be required to change your code when moving from one env to other env. You just have to take care of keeping the jndi name same in all the env.

  • Is this conditional WHERE clause possible?

    Let's say at the beginning of a stored procedure I do this:  DECLARE @hasActualHours BIT
    I'll then employ logic to set this local variable to either 0 or 1.
    I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause?
    For example:
    SELECT ...
    FROM ...
    WHERE
      Clause 1... AND
      Clause 2... AND
    Now, I have a Clause 3 but I
    only want to include it if @hasActualHours = 1.
    Is it possible to do something like that in T-SQL?
    Robert

    >> Let's say at the beginning of a stored procedure I do this:  DECLARE @hasActualHours BIT
    I'll then employ logic to set this local variable to either 0 or 1.
    I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause? <<
    No, no, no, no!  Your whole approach is totally wrong. Not a little wrong, but totally wrong. You just heard that from someone who helped write the SQL Standards, has 1200+ articles and 10 books on this topic. Please listen. 
    SQL is a declarative language, not a procedural flow control language. Declarative languages have no flow to control; there is no IF-THEN-ELSE, no loops. 
    SELECT ...
      FROM … 
     WHERE Clause 1... 
       AND Clause 2... 
       AND <expression for actual hour count> > 0.00;
    >> Is it possible to do something like that in T-SQL? <<
    Sure, we can kludge it! But first post a statement for your boss to see that you do not care about maintaining code, performance and professionalism. This would be bad for your career; like saying you eat babies on a parenting forum :) That is what the other
    replies are! 
    right now, you are the kid on a baseball diamond asking by which end do you hold the umpire. You are not thinking in SQL yet. My rule of thumb is you need a full year of SQL with a good mentor (read that last phrase again). It is a different mindset. 
    I wrote a book, THINKING IN SETS, to help with the change. See if that helps. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Conditional WHERE clause for APEX

    Dear SQL gurus,
    I know that there's a APEX forum, but I think that there maybe an sql based solution for this...
    What I have is a query like this:
    SELECT COMMENT_ORIG, COMMENT_CHARGING
    FROM  CL_INVENTORY_OPEN_OUT
    WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FK where :P13_INCIDENTAL_FK is a field in the Web Based GUI...
    What I need is to change the WHERE clause to something like this
    WHERE
      DECODE(:P13_INCIDENTAL_FK, NULL, 1=1, INCIDENTAL_FK=:P13_INCIDENTAL_FK)so to say:
    if the : P13_INCIDENTAL_FK is null, then let the clause be 1=1, otherwise let it be NCIDENTAL_FK=:P13_INCIDENTAL_FK.
    Is there a way to do this inside a sql statement?
    Best Regards and THX
    Johann

    SELECT COMMENT_ORIG, COMMENT_CHARGING
    FROM  CL_INVENTORY_OPEN_OUT
    WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FKDo not know how you are using the query, but you might try something like this
    BEGIN
      CASE :P13_INCIDENTAL_FK
        WHEN NULL THEN
          SELECT COMMENT_ORIG, COMMENT_CHARGING
            FROM  CL_INVENTORY_OPEN_OUT
        ELSE
          SELECT COMMENT_ORIG, COMMENT_CHARGING
            FROM  CL_INVENTORY_OPEN_OUT
           WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FK
      END CASE;
    END;Edited by: ajallen on May 7, 2010 6:44 AM

  • Interactive report - conditional where clause

    Hello,
    i have an interactive report like
    SELECT a.id, a.my_column
    FROM my_table a
    WHERE a.id = 12
    Now, when the user select a assigned value, the where clause don't be execute, also like this (without where)
    SELECT a.id, a.my_column
    FROM my_table a
    The User is not allowed to see this column, also i can not use the filter-function of the interactive report.
    Any Idea how did i make?
    thank's, Daniel
    Message was edited by:
    DaKa

    Hi Andy, this functionalitiy is clear.
    I will manipulate the region source in fact of an interaction of a user.
    Now, my select shows like:
    SELECT a.* FROM v_test a
    WHERE (:P40_ID = -1 OR a.id = :P40_ID)
    :P40_ID is a select box with return-null-value of "-1".
    This is not very fast. Therefore i search a method, when user select the null-value, then the select like:
    SELECT a.* FROM v_test a;
    and when user select another value then:
    SELECT a.* FROM v_test a
    WHERE a.id = :P40_ID;
    All this without the "filter"-functionality of the IR!
    Any idea?
    Sorry for this misunderstood.
    Daniel.

  • Plain SQL Conditional WHERE Clause with two sub-selects

    Hi SQL Experts,
    I need a bit quick of help with a query.
    This is a "select" statement for an OBI repository phyiscal table source object.
    So I cant put PL/SQL or Stored Procedures in it. I just need
    to have two different conditions/selects depending on the user role (this information comes
    from the session).
    The above, does not work:
    --------------ORA00905. 00000 -  "missing keyword"
      SELECT OFFICENO FROM orgunit
      WHERE
      CASE WHEN 'SESSION_VARIABLE' LIKE '%globalmanager%' THEN  
            ASSIGNEDOFFICES =
            SELECT DISTINCT ASSIGNEDOFFICES
            FROM USERSTABLE INNER JOIN orgunit ON
            orgunit.OFFICEKEY = USERSTABLE.OFFICEKEY
            WHERE USERSTABLE.USERNAME ='VALUEOF(NQ_SESSION.USER)'
      ELSE
            OFFICENO =
            SELECT DISTINCT OFFICENO FROM USERSTABLE
            INNER JOIN orgunit ON
            orgunit.OFFICEKEY = USERSTABLE.OFFICEKEY
            WHERE USERSTABLE.USERNAME ='VALUEOF(NQ_SESSION.USER)'
      END;   
    Can anyone help?

    Hi,
    I can't tell what you want to do just by looking at code that doesn't do it. Maybe:
    SELECT  officeno
    FROM    orgunit
    WHERE   (    session_variable  LIKE '%globalmanager%'
            AND  assignedofficies  IN
                     SELECT  assignedoffices
                     FROM    usertable  u1
                     JOIN    orgunit    o1  ON o1.officekey = u1.officekey
                     WHERE   u1.username    = 'VALUEOF(NQ_SESSION.USER)'
    OR      (    NVL ( session_variable
                     )        NOT LIKE '%globalmanager%'
            AND  officeno        IN
                     SELECT  officeno
                     FROM    usertable  u2
                     JOIN    orgunit    o2  ON  o2.officekey = u2.officekey
                     WHERE   u2.username   = 'VALUEOF(NQ_SESSION.USER)'
    There might be some simpler and more efficient way, depending on your tables and your reuirements.
    The condition u2.username   = 'VALUEOF(NQ_SESSION.USER)' is almost certainly not what you really want.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002#9362002

  • ALDSP 3.2 where clause in database query

    I am having trouble running a simple query against a Sybase 15.02 database from ALDSP 3.2 on WLS 10.1.
    I have the following function:
    declare function lib:test($test1 as xs:long?, $test2 as xs:long?) as xs:string{
    for $ADDRESS_LINK in add:ADDRESS_LINK()
    where $test1 = $ADDRESS_LINK/MASTER_ID or fn:empty($test1)
    where $test2 = $ADDRESS_LINK/CONTACT_ROLE_ID or fn:empty($test2)
    return
    $ADDRESS_LINK/INFO_REG_APPL_NAME
    When either of the parameters (test1 or test2) is set to null, there is no SQL execution.
    Any ideas on why it would be so?
    Here is the query plan:
    <FLWOR>
    <return>
    <variable kind="extracted" from="$f3477" name="(0)">
    </variable>
    </return>
    <for name="$f3477">
    <source kind="relational" tip="dssource" ns="fn-bea" name="dssource">
    <![CDATA[SELECT t1."INFO_REG_APPL_NAME" AS c1
    FROM DB."dbo"."ADDRESS_LINK" t1
    WHERE (((? = t1."CONTACT_ROLE_ID") OR (? = 1)) AND ((? = t1."MASTER_ID") OR (? = 1)))]]>
    <variable kind="EXTERNAL" name="__fparam1">
    </variable>
    <operator tip="{http://www.w3.org/2004/07/xpath-functions}empty" ns="fn" name="empty">
    <variable kind="EXTERNAL" name="__fparam1">
    </variable>
    </operator>
    <variable kind="EXTERNAL" name="__fparam0">
    </variable>
    <operator tip="{http://www.w3.org/2004/07/xpath-functions}empty" ns="fn" name="empty">
    <variable kind="EXTERNAL" name="__fparam0">
    </variable>
    </operator>
    </source>
    </for>
    </FLWOR>

    Please read Search Functionality
    The post from jhoffman with the code samples is the correct answer for ODSI 10.3.
    I'm not sure if that solution will work for ALDSP 3.2. There is an optimization rule in ODSI 10.3 that allows empty($variable) to be pushed to a database as 1=?, I'm not sure if that rule is in ALDSP 3.2. If you try Jeff's solution in ALDSP 3.2 and still have problems, I suggest using an ad hoc query.
    You asked why the sql does not get executed at all - for some databases/drivers, setting a parameter to null will cause an exception. In an effort to avoid that exception, the parameter is not set to null and the sql is not executed (unfortunately, this can give an incorrect result).

  • Select query with UNION clause in database adapter

    Friends,
    I have got a SQL query with two UNION clause withing it. like
    select a,b,c
    from a
    union
    select a,b,c
    from b
    The schema generated is like below in sequence
    <element>a</element>
    <element>b</element>
    <element>c</element>
    <element>a</element>
    <element>b</element>
    <element>c</element>
    So, the columns from different select queries joined with UNION clause are all appeared in schema instead of the distinct columns.
    Is there any way around to solve this issue ? or will need to with DB function/procedure.

    I think I know what you are saying but your example doesn't make sense, your SQL should produce something like
    I had to change a, b, c with elementA, elementB, elementC as a and b are reserved html tags.
    <elementA>DateA</elementA>
    <elementB>DataB</elementB>
    <elementC>DataC</elementC>
    ...What is the result of the query when you run it in SQLPlus? Is it what you expect?
    cheers
    James

  • List of values from Database Adapter - BPM Forms

    Hi all,
    Can anyone tell me how to get list of values from Database adapter and a ServiceTask.
    As example lets say a table has Employee and Department columns.
    I want to list down all the Employees in BPM form (Select One List Box) once i provide the department to the Database Adapter.
    Is it possible from the DB Adapter?? What will be the variable type?
    Thanks,
    Nir

    Hi DanielAtwood,
    Thanks for your reply...
    Actually when i send the variable in 'WHERE Clause' in Db Adapter query it will retrieve more than one record as the output.
    I want to put that values to a 'SelectOneChoice' component and list down all the values..
    First I tried with data control. But i couldn't find the way to pass the value to the variable(in WHERE clause) to the query in data control view.
    Thanks,
    Nir

  • How to use WHERE Clause in BPEL

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

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

  • Database Adapter Guide?

    I was looking though the Database Adapter samples and came across this statement in the readme file.
    Ways to avoid this problem are known as 'Polling Strategies', see the Database
    Adapter guide 'Choosing a Polling Strategy' to learn more.
    Where is the Database Adapter Guide located? I could not find it on my system, or doing a search on Oracle or Google.
    Any help is greatly appreciated.
    Thanks,
    Jim

    Try looking here
    http://download-east.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/toc.htm

  • Database Adapter - Dynamic where clause

    The database adapter needs to support a search facility.
    The user can search by any one of the following
    1) Date Range
    2) Primary Keys
    3) user who created
    Based on the above options, a query needs to be dynamically created in Database adapter
    Date Range
    select column1, column2 from emp where createddate  > ... and  createddate < ....
    Primary Key
    select column1, column2 from emp where empid in (1,2,3)
    * user who created*
    select column1, column2 from emp where userid= 456
    The conditions after the where clause vary dynamically.
    The pure sql option does not seem to support something like
    select column1, column2 from emp #whereclause
    Is there a way to do this in the Database Adapter?
    Edited by: user11920125 on Jan 14, 2010 11:57 AM

    If you are using SOA Suite 11g you can use query by example option to achieve part of that.
    It support only equality check but on dynamic number of fields
    Adam

  • Where clause for polling database Adapter

    I am creating a database adapter that polls a table for documents that are more than a month old based on a last updated field. For My where clause in the select statement I would like to have something like:
    where last_updated_date < add_months(sysdate, -1)
    but the where clause wizard will only allow me to use field names or literals. Any suggestions?

    Hi Stephen,
    Have you explored the option of calling a Stored Procedure or function which will do the SQL query as specified by you?
    Regards,
    lakshmi

  • Urgent: "where" clause for polling database Adapter

    Hi
    I am creating a database Polling (logical delete OPEN to CLOSED) adapter that polls a table for records which have a "SCHEDULED" date field.
    The Polling Adapter should pick up those records where the status is OPEN and SCHEDULED<=SYSDATE.
    DB Adapter wizard does not allows this where clause(SCHEDULED<=SYSDATE) to be set; so i tried modifying the Toplink SQL with custom SQL. But it does not works. Please suggest a workaround.
    Please help.
    Thanks
    Debashis

    Hi
    Please refer ..\SOA_HOME\bpel\samples\tutorials\122.DBAdapter\advanced\polling\PollingPureSQLOtherTableInsert Readme.txt and Note 873991.1 How To Use Custom SQL To Poll Database Tables Via Database Adapter LogicalDeletePollingStrategy.
    This works.
    thanks
    --debashis                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • MB5B - Stock on posting date show in other Unit of measure

    Dearl All, Pls support me this case: I would like to see this report (MB5B - Stock on posting date) in other Unit of measure. This report shows stock in Basic Unit only. E.g Material A, base unit = M, other unit = ROL Report needs show stock in ROL.

  • Acrobat DC - Adobe Sign-In Prompt

    If I install just Adobe Acrobat Pro DC using the Creative Cloud Packager, I've noticed that I receive an "Adobe Sign In" prompt every time I open Acrobat DC.  I can close this prompt and use the application without issue, but it's rather annoying.  I

  • Can't open iTunes - has error message - Hope someone might be able to help

    I had everything working about two weeks ago. I was able to download my CD's on the Nano.. Then my computer had to be reloaded with XP.. Lost iTunes..... I reinstalled it at least three times, but it will not work, even downloaded the new edition....

  • BUG IN JDEVELOPER !!! SQL QUERY

    Hi JDev Forumers ;o) I was wondering how I could accomplish to set my attribute labels and display the customized ones in a JSP page. I would like to display employee numer instead of empno, how did you do this? When i try to set the databse columns

  • POXPOEPO (11.5.10) - Lov for Item Number

    Dear All I need to modify the above form. I need to limit the item lov for items supplied by the vendor. I can achive this by relating it back to the sourcing rules. By how do i modify the sql of the lov. Its not implemented using the normal lov and