Where clause condition

How many conditions can will be applied in where clause and what is the maximum length for where condition?

eda58bb6-6d5c-460a-9684-4302e17fa5c7 wrote:
Thanks someoneElse for swift response. In this link it is not their.. WHERE CLAUSE Maximum length and maximum conditions.
unwilling or incapable to use GOOGLE yourself?
Ask Tom "maximum length of sql statement"
BTW - there is no separate & distinct limit for the WHERE clause
unless you what to consider below
Subqueries
Maximum levels of subqueries in a SQL statement
Unlimited in the FROM clause of the top-level query255 subqueries in the WHERE clause"

Similar Messages

  • Sequence of tables in from clause and sequence of "where clause" conditions

    Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?
    Edited by: user6763079 on Jun 1, 2011 3:33 AM

    user6763079 wrote:
    Is Sequence of tables in "From Clause" and sequence of "where clause" conditions matters in 10g for performance?In general it does not matter.
    It could matter if the Rule Based Optimizer (RBO) is used. However this RBO is only used if enforced by a hint or if no table statistics are collected. Starting from 10g the table statistics are automatically selected by a regular database job. So in general the CBO would be used.
    The CBO will consider different access paths. If the number of tables is low enough, then all possible combinations are considered and the order does not make any difference.
    Edited by: Sven W. on Jun 1, 2011 4:00 PM

  • Including additional where clause conditions to view criteria dynamically

    Hi,
    We have a set of view objects that serves as LOV for various other view objects. All such LOV view objects have three specific attributes, two date attributes namely EffectiveStartDate, EffectiveEndDate and a String attribute namely UserSwitch based on which the LOV list needs to be filtered.
    All the view objects are having one or more view criterias with specific where clause conditions.
    Apart from those view criteria conditions, invariantly, we need the following conditions also
    :bindEffDate between EffectiveStartDate and EffectiveEndDate and UserSwitch = :bindUserSwitch.
    We wish not to include the above condition in each and every view criteria of each and every view object (Since we have around 800 view objects and a minimum of 2 view criterias per view object). Instead, we created a dummy view object (BaseViewObject) with two bind variables :bindEffDate and :bindUserSwitch and all the LOV view objects were made to extend this BaseViewObject.
    Therefore, whenever a view object atribute is attached with LOV using the above said LOV View Objects, the bind variables of the baseViewObject as well as the view object specific bind variables are available in the view accessors tab of the view object wizard where we can supply values to those bind variables.
    Now, we need to construct the view criteria filter clause. To achieve this, we created a class, CustomCriteriaAdapter.java extending oracle.jbo.server.CriteriaAdapterImpl. In the getCriteriaClause() method, we included the follwoing code:
    public String getCriteriaClause(ViewCriteria pViewCriteria)
    ViewObject vo = pViewCriteria.getViewObject();
    String userSelectSwitch = (String) vo.ensureVariableManager().getVariableValue("bindUserSwitch");
    String effBgnDt = vo.getAttributeDef(vo.getAttributeIndexOf("EffectiveStartDate")).getName();
    String effEndDt = vo.getAttributeDef(vo.getAttributeIndexOf("EffectiveEndDate")).getName();
    String customCriteria = " ( :bindEffDate >= " + effBgnDt + " ) AND ( :bindEffDate <= " + effEndDt + " OR " + effEndDt + " IS NULL ) ";
    StringBuffer completeCriteria = new StringBuffer();
    String criteriaClause = super.getCriteriaClause(pViewCriteria);
    if (criteriaClause != null && !criteriaClause.isEmpty())
    completeCriteria.append(criteriaClause + " AND ");
    completeCriteria.append(customCriteria);
    if (userSelectSwitch != null && "Y".equals(userSelectSwitch))
    String userSelectSw = vo.getAttributeDef(vo.getAttributeIndexOf("UserSwitch")).getName();
    completeCriteria.append(" AND (" + userSelectSw + "='Y' ) ");
    return completeCriteria.toString();
    Issues:
    The LOV list is not filtering the records based on the constructed conditions. Instead it is listing either all of the records considering only the view criteria conditions applied at design time irrespective of the userswitch and effectivedate conditions or the list is empty.
    Here, my questions are,
    1. Am I in the correct approach? If not, guide me in a more proper approach to achieve the same requirement.
    2. If the way I am trying is correct, where things are going wrong and why the dynamic condition is not getting effected?
    Kindly help in sorting out the issue.
    Thanks in advance.

    Hi Jobinesh,
    Thanks for your response and yes, we have done exactly as what you have mentioned. As explained earlier, a baseViewObject along with its Impl class has been created and it will be extended by all the viewobjects meant for serving LOV. Therefore, the superClass for any such LOV viewObject is the baseViewObjectImpl class. In that baseViewObjectImpl(), we have over-rided the criteriaAdapter() method and returned an instance of our customCriteriaAdapter() class.
    Below is the code we are using in the baseViewObjectImpl():
    package model.base.vo;
    import oracle.jbo.CriteriaAdapter;
    import oracle.jbo.server.ViewObjectImpl;
    public class BaseViewObjectImpl
    extends ViewObjectImpl
    * This is the default constructor (do not remove).
    public BaseViewObjectImpl()
    * Over-rided method of ViewObjectImpl class of the framework.
    * Calls the customized criteria adapter so that the default where clauses are added to the view criteria.
    * @return CriteriaAdapter.
    @Override
    public CriteriaAdapter getCriteriaAdapter()
    return new CustomCriteriaAdapter();
    I'll create a sample in HR schema and share with you shortly.
    Thanks and regards.

  • In which order does the query's where clause condition is checked

    Hi All,
    can anyone tell me in which order does oracle evaluate the where clause condition?
    for ex: select * from users where user_type='Admin' and stauts='Enabled'

    user9981103 wrote:
    The conditions in the WHERE clause are checked in the reverse order of the given order.
    i.e; first it will check stauts='Enabled'* and then user_type='Admin'* for your given queryWhy do you believe that?
    If there is a sufficiently selective b-tree index on USER_TYPE, the optimizer would undoubtedly use that index to process the USER_TYPE = 'Admin' condition and then check the STATUS column.
    If there is a sufficiently selective b-tree index on STATUS, the optimizer would undoubtedly use that index to process the STATUS='Enabled' condition and then check the USER_TYPE column.
    If there is a composite b-tree index on (STATUS, USER_TYPE), the optimizer would use that index to process the two conditions nearly simultaneously, though technically the leading column of the index is evaluated first. Of course, if you reverse the order of columns in the index, you get a different evaluation order
    If there are bitmap indexes on STATUS and USER_TYPE, Oracle can combine the two indexes and evaluate the two conditions simultaneously.
    And that is leaving out tons of query plan options and other optimizer wrinkles.
    Justin

  • Need Help on where clause condition

    Hello All,
    Thanks in advance::
    I have below SQL query which is returning 1500 records when i dont use any condition in where clause(Please see the query below);
    SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID,
    CHRG,
    DOC,
    NULL,
    ACNT_RLN,
    ACCOUNT_FLODERS_VER,
    DM_LSTUPDDT,
    DM_BTNUMBER,
    DM_USERID,
    DM_WSID,
    STAT_FLG,
    SERVICES_FLG,
    SERVICES,
    INTRST_COND,
    PST_INSTRN
    FROM &&SRC.ACCOUNT_FOLDERS,
    &&SRC.DB;
    Output: 15 rows retured
    And when i validate the data by putting some conditions in where clause , it is giving 1499 records ( Please see the query below with condition )
    SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID,
    CHRG,
    DOC,
    NULL,
    ACNT_RLN,
    ACCOUNT_FLODERS_VER,
    DM_LSTUPDDT,
    DM_BTNUMBER,
    DM_USERID,
    DM_WSID,
    STAT_FLG,
    SERVICES_FLG,
    SERVICES,
    INTRST_COND,
    PST_INSTRN
    FROM &&SRC.ACCOUNT_FOLDERS,
    &&SRC.DB
    WHERE (POS_TYPE,
    POS_ID,
    SUB_ACNT_ID) IN (SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID FROM ACCOUNT
    WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE OR 1_FIRST_RUN_FLAG=1);
    Now, I wanted to know that missing record(1st SQL is giving 1500 rows without any condition & 1nd SQL is giving 1499 rows with condition in where clause)
    I am worried and confused to find out the missing record. Tried with different conditions like Not In... nothing worked perfectly.
    Could some one please have a look and provide me the correct SQL , Performance wise also it should be good, SQL should not cause any performance issues.
    Please help me on it..
    Thanks,
    MKR

    Do a minus
    SELECT POS_TYPE,
           POS_ID,
           SUB_ACNT_ID,
           CHRG,
           DOC,
           NULL,
           ACNT_RLN,
           ACCOUNT_FLODERS_VER,
           DM_LSTUPDDT,
           DM_BTNUMBER,
           DM_USERID,
           DM_WSID,
           STAT_FLG,
           SERVICES_FLG,
           SERVICES,
           INTRST_COND,
           PST_INSTRN
      FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB;
    MINUS
    SELECT POS_TYPE,
           POS_ID,
           SUB_ACNT_ID,
           CHRG,
           DOC,
           NULL,
           ACNT_RLN,
           ACCOUNT_FLODERS_VER,
           DM_LSTUPDDT,
           DM_BTNUMBER,
           DM_USERID,
           DM_WSID,
           STAT_FLG,
           SERVICES_FLG,
           SERVICES,
           INTRST_COND,
           PST_INSTRN
      FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB
    WHERE (POS_TYPE, POS_ID, SUB_ACNT_ID) IN (SELECT POS_TYPE, POS_ID, SUB_ACNT_ID
                                                 FROM ACCOUNT
                                                WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE
                                                   OR  1_FIRST_RUN_FLAG = 1);  G.

  • How to reverse where clause condition? please

    Hello Good Morning,
    i have below query which is working fine,
    update t
    set skipjet='Yes'
    from  mytable t join mychildtable C on t.ssn=c.ssn
    where
    t.ChannelCd ='OB Calls' AND t.PlanBlance BETWEEN c.MinSalary  AND  c.MaxSalary
    but my problem here is, i have to set skipjet='Y' when the above where clause not met (like opposite way)
    Please advise?
    Thank you in Advance
    Asita

    Dear Milano, 
    I did an example and i got the result that you needed.
    declare @mytable table (ssn int,ChannelCd varchar(50),PlanBlance money,skipjet varchar(3))
    declare @mychildtable table (ssn int,MinSalary money,MaxSalary money)
    insert into @mytable(ssn,ChannelCd,PlanBlance,skipjet) values (1,'OB Calls',800.00,'NO')
    insert into @mytable(ssn,ChannelCd,PlanBlance,skipjet) values (1,'OB Calls2',800.00,'NO')
    insert into @mychildtable(ssn,MinSalary,MaxSalary)values(1,600.00,800.00)
    update t set skipjet='Yes'
    from
    @mytable t
    where
    not exists (
    Select * from
    @mychildtable C
    where
    t.ssn=c.ssn and
    t.ChannelCd ='OB Calls' AND
    t.PlanBlance BETWEEN c.MinSalary AND c.MaxSalary
    Select * from @mytable
    Result:
    ssn         ChannelCd                                      PlanBlance           skipjet
    1           OB Calls                                           800,00                NO
    1           OB Calls2                                         800,00                Yes
    (2 row(s) affected)
    Ricardo Lacerda
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Different WHERE clause condition

    Guys,
    What the below statement denotes ?
    sd.account_type_key = act.account_type_key()
    what is mean by () ?

    Any chance of object types with member functions being involved..
    SQL>CREATE TYPE object_typ AS OBJECT (
      2    object_id         Number(4),
      3    object_name       Varchar2(128),
      4    MAP MEMBER FUNCTION get_idno RETURN NUMBER
      5    ) ;
      6  /
    Type created.
    SQL>
    SQL>CREATE TYPE BODY object_typ AS
      2    MAP MEMBER FUNCTION get_idno RETURN NUMBER IS
      3    BEGIN
      4      RETURN object_id;
      5    END;
      6  END;
      7  /
    Type body created.
    SQL>SELECT y.object.get_idno() from
      2  (
      3  select  object_typ ( object_id, object_name ) object
      4  from  dba_objects
      5  where object_id < 10
      6  ) y
      7  /
    Y.OBJECT.GET_IDNO()
                      2
                      3
                      4
                      5
                      6
                      7
                      8
                      9
    8 rows selected.

  • Where clause and order by to DAO classes

    Hi
    Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?

    Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
    Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
    1. The following code would populate a purchase order's details given an id.
    private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
    PurchaseOrderModel getPurchaseOrderData(long poId){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the poId passed as params to your query
         pst.setLong(1, poId);
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //populate data into a model          
         finally{
              //clean up resources
         return model;    
    }2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
    private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
    PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(QUERY_1);
         //set the dates passed as params to your query
         //we know that the List ought to contain only 2 dates
         pst.setDate(1, (Date)bindValues.get(0));
         pst.setDate(2, (Date)bindValues.get(1));
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
         3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
    private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
    PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
         //construct the query dynamically
         StringBuffer query = new StringBuffer(QUERY_3);
         int count = 0;
         for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
              String value = (String)itr.next();
              query.append ("name like 'value%' ");
              if (count != 0 and (count+1 != bindValues.length)){
                   query.append(" or ");
              count ++;          
         //get a prepared statement from your connection
         PreparedStatement pst = conn.prepareStatement(query.toString());     
         ResultSet rs = pst.executeQuery();
         if(rs.next()){
              //iterate and populate data into a model          
              //add model to a list
         finally{
              //clean up resources
         return list;    
    To sum up,
    1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
    2. The ejb/business layer would examine the data and decide on which method to call.
    3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
    Having said that, it really is your decision - you should take into consideration the following factors -
    1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
    2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
    3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
    4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
    You should take into account all these before deciding to go one way or the other.
    A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
    cheers,
    ram.

  • Dynamic Where clause - from third party system

    I have internal table A with fields I am getting from legacy system
    field1
    field2
    field3
    field4
    fieldn
    and i am getting a condition table (Where clause conditions) from a legacy system thru an RFC call.
    and in the RFC i need to delete records from internal table A using this where clause
    and where clause condition table(is 72 char length single field table) from legacy system looks like the following
             ( FIELD1                          BETWEEN '01' AND '05' ) AND
         FIELD1                         NE '06'
         AND ( FIELD4                     EQ 'BU' )
         AND ( FIELD5                      BETWEEN '001' AND '009' )
    How could i delete entries from internal table A using this where clause conditon table mentioned above

    Hi a®s,
    yes, thats what I thought of: Generate subroutine Pool.
    I did not elaborate on the fact that dynamic where clauses are allowed only for database selections. That means that FUNCTION 'FREE_SELECTIONS_WHERE_2_RANGE' can't be used either.
    But if you generate a subroutine, you can generate TYPE and DATA declarations as well. This gives you the ability to have static where condition for the DELETE itab WHERE statement.
    If the type vaies during runtime, the generation may vary too.
    I think you are able to do the coding for this.
    On the other hand, Thomas' 'slick' proposal using a temporary database table and a subsequent SELECT ... WHERE (<dynamic where clause) may be easier to implement.
    BTW: Are ther release notes on ABAP720?
    Regards,
    Clemens

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

  • How can I pass multiple condition in where clause with the join table?

    Hi:
    I need to collect several inputs at run time, and query the record according to the input.
    How can I pass multiple conditions in where clause with the join table?
    Thanks in advance for any help.
    Regards,
    TD

    If you are using SQL-Plus or Reports you can use lexical parameters like:
    SELECT * FROM emp &condition;
    When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
    SELECT &columns FROM &tables &condition;
    But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
    Best of luck!

  • 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

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

  • Where clause with conditions

    Hi all,
    I have a report that is to be filtered based on user input into a text field and drop down list.
    The goal is to let the user enter either an exact value (based off auto-complete functionality), or use the wildcard character, %
    This is where the drop down comes in. If they select value1, the autocomplete, exact value is used and the where clause would look like something below,
    select col1, col2, col3
    from table
    where :P1_FILTER in (select distinct col2 from another_table)If they select value2, then the where should process using the like function and %s. Something like,
    select col1, col2, col3
    from table
    where :P1_FILTER like (select distinct col2 from another_table)How can I take care of this in 1 where clause? I'm sort of stuck trying to figure it out.
    Thank you for any help.
    -Chris

    I don't believe the way you have it coded is correct.. Can you move it over o SQL Developer of the SQL Commands page in APEX and trying running your query? If it doesn't work there then your SQL is coded wrong.
    Since you are trying to have One or The Other condition be used for your query, I would think the Function returning Sql Code would be the obvious selection, but I could be wrong here...
    Thank you,
    Tony Miller
    Webster, TX
    A lady came up to me on the street, pointed at my suede jacket and said "Do you know a cow was murdered to make that jacket?"
    "I didn't know there were any witnesses", I replied " Now I'll have to kill you too"

  • 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

Maybe you are looking for