WHERE clause order ox performance question

I do not understand order of execution of a WHERE clause, the use of a complex database

I want to write a SELECT statement with the following condition

... WHERE (branch = 'main') AND (type = 1) OR (AND the costs-1 = 2).

My question is

< 1 > yoyu can use parentheses within a WHERE clause

< 2 > how you would write such a clause as above if you cannot use parenthesis

Thank you

Hello

Yes, you can have parentheses in a WHERE clause.
I highly recommend to use when you need to use both AND and or in the same WHERE clause, since

WHERE  (    x
        AND y
        )
OR      z

is not the same as

WHERE   x
AND     (   y
        OR  z
        )

As others have said:

( charge -1 AND charge = 2 )

will cause a compilation error.
Here's the syntax valid and quite reasonable (although somewhat obscure):

WHERE     (     branch = 'main'
     AND     type    = 1
     )
OR          (     charge != -1
        AND     charge !=  2
     )

Tags: Database

Similar Questions

  • Columns in the WHERE clause - order affect the output?

    I work on some queries to feed a DWH and stumbled upon this question. Let's say I have this query:
    (SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1
                    where aa.artid=tc1.artid
                    and t.tocid=tc1.tocid
                    and aa.abocod=c.abocod
                    and aa.artconcod=c.concod
                    and aa.percod=a.percod
                    and aa.ArtAboFlgA='S'
                    ) Tarjeta
    The exit will happen anyway if I do like this:
    (SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1
                    where aa.artid=tc1.artid
                    and a.percod=aa.percod
                     and aa.ArtAboFlgA='S
                    and tc1.tocid=t.tocid
                    and c.abocod=aa.abocod
                    and aa.artconcod=c.concod
                     ) Tarjeta
    I guess what he used, or at least I him did not change with the data that I use, but I thought to check here once just to have peace of mind. Maybe it's not the happiest example, but I guess the question is clear

    No difference.

  • alias in where clause

    Hello

    It is a question of OCA certification.

    1. SQL > SELECT prod_name, prod_list_price, prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE".
    PRODUCTS
    WHERE the discounted_price < 10;

    The query generates an error.
    What is the reason for generating fault?
    A. the parentheses should be added to frame the entire expression
    B. the quotes should be removed from the column alias
    C. column aliases must be replaced by the expression in the WHERE clause
    D. column aliases must be capitalized and closed double quotes in the WHERE clause

    Answer: D


    My question is how we can use aliases ("DISCOUNTED_PRICE") in where clause (WHERE "DISCOUNTED_PRICE" < 10)?

    Please specify.

    Hello

    C. response (and I think, you not write review at this time)

    You cannot use alias name in the WHERE clause.

    And if you want to continue to use DISCOUNTED_PRICE in the WHERE clause, you can use view inline.

    SELECT *
    FROM (SELECT prod_name,prod_list_price,prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE"
    FROM products
    )
    WHERE  WHERE discounted_price<10;
    

    See you soon,.
    Suri

  • Question about the order of evaluation of the clause WHERE CLAUSE when the Oracle OF the syntax used to join tables

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?

    Thanks in advance,

    Hello

    dariyoosh wrote:

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...

    The reverse is actually closer to the truth, but we can't really make general statements like that.

    SQL is not a language of the proceedings.  Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it.  In other words, SQL is a language that describes the results you get, not the way to get them.

    The optimizer will do everything what he thinks is faster if it does not change the results.  If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.

    Here is a query looks very much like you posted:

    SELECT d.deptno

    e.ename, e.sal

    OF scott.dept d

    LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno

    WHERE e.sal > = 3000

    ORDER BY d.deptno

    ;

    Output:

    DEPTNO ENAME SAL

    ---------- ---------- ----------

    10 KING 5000

    20 FORD 3000

    20 3000 SCOTT

    The scott.dept table contains deptnos 30 and 40; Why are they not in the result set?  The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied.  All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.

  • Order columns (which make up the primary key constraint) matter in where clause of DML query for use of indexing mechanism to operate.

    Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production


    I have a table my_table as below:
    create table my_table
    (
    my_code varchar2 (6).
    my_id varchar2 (24).
    forced pk_1 primary key (my_code, my_id)
    );


    Primary_key here's a composite key that contains columns 1 (my_code) and 2 (my_id).
    Is there that a difference in the way below queries is executed in terms of performance (use of indexing in the extraction).

    (a) select * from my_table where my_code = '123' and my_id = "456";
    (b) select * from my_table where my_id = '456' and my_code = '123';


    The understanding I have the order of the column in the where clause should be identical to the sequence in
    What primary key draws for indexing to be used by oracle in oracle other DML queries ignores indexing
    However when I used explain plain both show the same query cost with single scan with index rowid.
    so I don't know if I'm wrong in the concept that I have. Kindly help.

    Thanks in advance,
    Gerard

    Your question is answered in the Performance Tuning Guide

    Using indexes and clusters

    14.1.4 choosing composite indexes

    A composite index contains several key columns. Composite indexes can provide additional benefits compared to the index to single column:

    • Improved selectivity

      Sometimes the two or more columns or expressions, each with a low selectivity can be combined to form a composite with a high selectivity.

    • Reduced IO

      If all columns selected by a query are a composite index, then Oracle may return these values in the index without access to the table.

    A SQL statement can use a path on a composite index if the statement contains constructions that use a main part of the index.

    Note:

    This is no longer the case with the skip index scans. See "Index Skip Scans".

    A main part of an index is a set of one or more columns that have been specified first and consecutively in the list of columns in the CREATE INDEX statement that created the index.

  • Details on the order of columns in a Where Clause

    Hi All
    My both Quarries  are giving same record count .
    so  can  i say that the order of the columns("msib.inventory_item_id=pol.item_id" AND" pol.item_id=msib.inventory_item_id ") 
    in the where  clause doesn't effect the query result in any situation 
    {code
    }
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pll.ship_to_organization_id = msib.organization_id ----------------1
    and msib.inventory_item_id=pol.item_id --------------------------2
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    group by 1
    
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pol.item_id = msib.inventory_item_id  ----------------------------------2 
    and pll.ship_to_organization_id = msib.organization_id -----------------------------1 
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    Thank you

    Published by: vijay539 on November 20, 2009 09:17

    Published by: vijay539 on November 20, 2009 09:18

    Published by: vijay539 on November 20, 2009 09:19

    Published by: vijay539 on November 20, 2009 09:19

    Hello

    Right; the order in which the columns appear in the SELECT clause has nothing to do with the lines that are in the result set.

    In fact, unless you say SELECT DISTINCT , I don't think there's anything (except to trigger an error) you can do in the SELECT clause, which would change the lines are selected.

    Published by: Frank Kulash, November 20, 2009 12:45

    Sorry, I misread the question. You may have about the order of the conditions in the WHERE clause, not the SELECT clause.

    The answer in short is the same:
    Right.

    Unless you mix ANDS and ORs (no one should ever do and that you are not), the order of the conditions will make no difference in the results.

  • Question of WHERE Clause.

    All, I was just doing some checking at random and came across the following query

    SELECT * FROM emp WHERE +empno > 0;
    

    My question is that oracle runs the query above without any error. What is the use of such expressions in where clause and why the compiler does not throw error for these?

    I've never met such scenario. Just tried your query and it works. The reason is below.

    Look at what makes this request.

    SELECT - empno FROM emp;

    OUTPUT:

    -EMPNO
    ----------
    -7369
    -7499
    -7521
    -7566
    -7654
    -7698
    -7782
    -7788
    -7839
    -7844
    -7876

    -EMPNO
    ----------
    -7900
    -7902
    -7934

    14 selected lines.

    So you might see if you add a minus sign before the name of the column, it converts only for negative values.

    So, even if you add a sign "+", since these are positive values (> 0), your condition succeeds and gives the result. See what would happen if you used - empno in which your condition.

    SQL > SELECT * FROM emp WHERE empno - > 0;

    OUTPUT:

    no selected line

    Hope you clear how it works.

  • Question about WHERE Clause

    Hello

    I'm doing a conditional clause where clause displays the lines in a report.

    The desired control is date of two fields (CIC and announcement) must all be virgins or someone not be an 'Admin' (taken from a global variable stored on connection) for her to no display.

    Here's what I have:

    WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN IS NOT NULL AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    During the test of this query, it hides a field with ONE of the two dates being blank and which is not desirable.

    I also tried to write it like this and got an error of analysis for an invalid relational operator:

    WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    Any help would be greatly appreciated. Please let me know if I need to clarify.

    I take what I said back.  Your requirement of "double negative" is odd

    DO NOT SHOW: where (X is null and Y is null)

    translates

    Show: where not (x is null and Y is null)

    WHERE NOT (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN is null AND DATACOLLECT. CHANGE_IN_CONTROL IS NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    MK

    PS - this is a thing of database.  PL/SQL and SQL would have been a better choice

  • Where-Clause-Question by using "defined values.

    Hello

    I use 10 gr 2

    It is possible to filter the lines using sets of values in the where clause?

    As for example:
    SELECT a, b, c
      FROM mytable
      WHERE (b,c) IN
        (
          (3,4),
          (6,7),
          (9,1),
          (0,2)
        )
    .. must retrieve only the rows from myTable with sets (pairs) over the top of the list

    It is not difficult to test:

    with my_tab as (select 1 a, 2 b, 3 c from dual union all
                    select 2 a, 2 b, 2 c from dual)
    select * from my_tab
    where (b, c) in ((1,2), (2,3));
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    
  • Setting in the WHERE clause of the query

    Hi all

    I have 2 tables.

    TABLE_A contains 10 million documents.
    TABLE_B contains 100 records.

    I associate myself with these 2 tables

    Here's a.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE a.ID = b.ID;
    Here's b.ID left
    SELECT A.*, B.*
    FROM TABLE_A a, TABLE_B b
    WHERE b.ID = a.ID;
    My question is what query will give better performance? I thought that, if we put the column in the table with a lower number of lines on the left, then it will be faster than the other.

    In current versions of Oracle, it does not matter in what order you sum-up your predicates in the WHERE clause of a query: they will be optimized/executed in a way even.

  • dynamic where clause ofa

    Dear all,

    I have a problem in the dynamic where clause in the OPS.

    I have a VO query as below:

    SELECT desc, ccuid, containid, XXXTMP conainline

    I'll put whereclause as below:

    VO.setwhereclause ("containid '101' =" + "order by containline desc")

    so the question is request forms as below:

    SELECT desc, ccuid, containid, XXXTMP conainline

    (where containid = '101' containline desc order) -query gives question, adding the command from the inside of the caliper

    Ideally, order by clause should come outside of the Stirrup.

    so, how do I do order by clause order side where clasue or how do I remove the stand before the where clause. So I need the query as below:

    SELECT desc, ccuid, containid, XXXTMP conainline

    (where containid = '101' containline desc order)

    SELECT desc, ccuid, containid, conainline from XXXTMP where containid = '101' containline desc order

    or

    SELECT desc, ccuid, containid, XXXTMP conainline

    (where containid = '101') order by containline desc

    Thank you

    Hello

    Solution 1-

    You can use "setOrderByClause (containline desc);" so that it will get out of Where clause.

    Solution 2-

    Instead of dynamically add Whereclause, you can bind the variable as below-

    Query in VO-

    SELECT desc, ccuid, containid, conainline from XXXTMP where containid =: 1 containline desc order


    In VOImpl-

    public void initQuery (String variable)

    {

    clearCache();

    setMaxFetchSize(-1);

    setWhereClause (null);

    setWhereClauseParams (null);

    setWhereClauseParam (0, variable);

    executeQuery();

    }

    Vall of this VOImpl method, and pass the variable value. It will work according to your requirement.

    Thank you

    Kone

  • Export (expdp) with where clause

    Hello gurus,

    I'm trying to export with where clause. I am getting error below.


    Here is my order of export.
    expdp "'/ as sysdba'" tables = USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= “USER1.TABLE1:where auditdate>'01-JAN-10'”
    Here is the error
    [keeth]DB1 /oracle/data_15/db1> DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate>'01-JAN-10'                    <
    
    Export: Release 11.2.0.3.0 - Production on Tue Mar 26 03:03:26 2013
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Starting "SYS"."SYS_EXPORT_TABLE_03":  "/******** AS SYSDBA" tables=USER1.TABLE1 directory=DATA_PUMP dumpfile=TABLE1.dmp logfile=TABLE1.log query= USER1.TABLE1:where auditdate
    Estimate in progress using BLOCKS method...
    Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 386 MB
    Processing object type TABLE_EXPORT/TABLE/TABLE
    Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
    Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type TABLE_EXPORT/TABLE/TRIGGER
    Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
    ORA-31693: Table data object "USER1"."TABLE1" failed to load/unload and is being skipped due to error:
    ORA-00933: SQL command not properly ended
    Master table "SYS"."SYS_EXPORT_TABLE_03" successfully loaded/unloaded
    ******************************************************************************
    Dump file set for SYS.SYS_EXPORT_TABLE_03 is:
      /oracle/data_15/db1/TABLE1.dmp
    Job "SYS"."SYS_EXPORT_TABLE_03" completed with 1 error(s) at 03:03:58
    Version
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production

    Hello

    You must use the settings file. Another question, I see you are using 11g. Why don't you use a data pump.?
    Data pump is faster and has more features and that regular improvement imp and exp.

    You can do the following:

    sqlplus / as sysdba
    
    Create directory DPUMP_DIR3  for 'Type here your os path that you want to export to';
    

    then tap on a file:
    Touch par.txt

    In this file, type the following line the following:

    tables=schema.table_name
    dumpfile=yourdump.dmp
    DIRECTORY=DPUMP_DIR3
    logfile=Your_logfile.log
    QUERY =abs.texp:"where hiredate>'01-JAN-13' "
    

    then proceed as follows
    expdp username/password name parfile = 'par.txt'

    You will import to Oracle 11 g to 10g version should add 'version = 10' parameter in the above setting file

    BR
    Mohamed enry
    http://mohamedelazab.blogspot.com/

  • Very Urgent: Setting dynamic where clause for Popup list VO

    Hello world


    It is a very urgent requirement please help as soon as possible.


    I have a custom page in iSupplier. I created two supplier site, number of PO fields.

    Site of beg - choice of Message and PO number - Message LOV of entry


    I have a named VO under xxisupplier.oracle.apps.pos.home.poplist.server for site begging and xxisupplier.oracle.apps.pos.home.lov.server for PO number.

    I have joined these two VO AM homepage.




    Now the question is

    1. I want to restrict these VO vendor_id-based so I'll put dynamically where clause for these two VO of in my CO


    VO SITE PROVIDER QUERY


    SELECT POVs.vendor_site_code site, pov.vendor_id
    OF po_vendors pov, povs po_vendor_sites_all
    WHERE pov.vendor_id = povs.vendor_id
    AND TRUNC (povs.inactive_date) IS NULL


    PO NUMBER LOV QUERY VO


    SELECT DISTINCT ai.invoice_num, ai.vendor_id, ai.invoice_date, poh.segment1
    AI ap_invoices_all,.
    help ap_invoice_distributions_all,
    po_headers_all poh,
    po_distributions_all pda,
    Al ap_lookup_codes
    WHERE aid.po_distribution_id = pda.po_distribution_id
    AND ai.invoice_id = aid.invoice_id
    AND poh.po_header_id = pda.po_header_id
    AND ai.invoice_type_lookup_code = al.lookup_code
    AND al.lookup_type = 'INVOICE TYPE'


    I am creating where cluase as below in CO



    If (vendor_id1! = null)
    {
    System.out.println ("vendor_id:" + vendor_id1);
    OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject ("PO_LOV_VO");
    if(vo!=null)
    {
    vo.clearCache ();
    VO. Reset();
    System.out.println ("inside IN. VO:" + vendor_id1);
    vo.setWhereClause (null);
    vo.setWhereClause ("vendor_id =: 1");
    vo.setWhereClauseParams (null);
    vo.setWhereClauseParam(0,vendor_id1);
    vo.setOrderByClause ("invoice_date DESC");
    String INVQRY = vo.getQuery ();
    System.out.println ("INVQRY:" + INVQRY);
    vo.executeQuery ();
    VO. First();
    System.out.println ("after the query appear" + vo.getRowCount ());
    }

    OAViewObjectImpl sitevo1 = (OAViewObjectImpl) am.findViewObject ("SUPPLIER_SITE_VO1");
    if(sitevo1!=null)
    {
    sitevo1.clearcache ();
    sitevo1. Reset();
    System.out.println ("Interior site:" + vendor_id1);
    sitevo1.setWhereClause (null);
    sitevo1.setWhereClause ("vendor_id =: 1");
    sitevo1.setWhereClauseParams (null);
    sitevo1.setWhereClauseParam(0,vendor_id1);
    String SITEQRY = sitevo1.getQuery ();
    System.out.println ("SITEQRY:" + SITEQRY);
    sitevo1. ExecuteQuery();
    sitevo1. First();
    System.out.println ("after the query appear" + sitevo1.getRowCount ());
    }



    Here he works for the purchase order number but the where cluase does not work for Supplier Site. Please help as soon as possible.


    2 and also if supplier site to return multiple values then this field should show as messagechoice. If it returns a single value, then it should be the style text message
    How can I achieve this.



    Thank you
    CSK

    Try

    vo.setWhereClause ("IN vendor_id (" + vendor_id_qry + ")" ");

    vendor_id_qry is the query that retrieves the list of provider IDS. You don't need to put the vendor column id as whereClauseParam unless you want to have IN the clause in your query of VO and pass the list as 1,2,3 values to the parameter.

    Thank you
    Shree

  • Using cfif in a where clause clause

    Hi all

    This question is somewhat related to a previous post of mine on the polling dates.  I'm trying to use a cfif statement in my where clause to determine if a field is empty or not.  Here is the code:

    < cfquery name = "GetPastEvents" datasource = "DSN" >

    SELECT *.

    SITE: calendar

    WHERE DatePart ("yyyy", [StartDate]) = < cfqueryparam value = ' #Dateformat (Today, 'yyyy') # "cfsqltype = 'CF_SQL_DATE' / >

    and < cfif EndDate NEQ "> < cfelse > StartDate, EndDate < / cfif > < < cfqueryparam value =" "#Today #" cfsqltype = 'CF_SQL_DATE' / > "

    and Archive = < cfqueryparam value = '0' cfsqltype = "CF_SQL_INTEGER" / >

    ORDER BY StartDate ASC, StartTime ASC

    < / cfquery >

    My question that this CF tells me EndDate is not defined.  EndDate is a field in the SITE table: calendar.  There must be a way to make this work, no?  Thank you!

    You mix the ColdFusion variables (required by cfif) and SQL column names. Think of it this way, all CF tags and function run before the SQL query is sent to SQL server. You are this mixture and try to run CF instruction on SQL Server and thus fail.

    You need something like this:

    SELECT *.

    SITE: calendar

    WHERE DatePart ("yyyy", [StartDate]) =

    and)

    (enddate is not null and EndDate <> )

    or (enddate is null and StartDate <> )

    )

    and Archive =

    ORDER BY StartDate ASC, StartTime ASC

    Also, I think your logic cfif was back. Instead of NEQ I think you meant EQ because having an EndDate EQ "and then comparing EndDate until today (else clause) makes no sense.

  • Case statement in a WHERE clause

    Gurus,

    Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.

    Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.

    and case  when 'New Items' = 'xxx' --p_item_status 
             then  msi.creation_date = msi.last_update_date
          when 'Updated Items' = 'bbb' --p_item_status  
             then  msi.creation_date != msi.last_update_date
          else 1=1
    end;  
    Points for correct and helpful answers!

    Published by: sreese on March 27, 2012 17:51

    Hello

    The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:

    WHERE     (     :p_item_status        = 'New Items'
         AND     msi.creation_date  = msi.last_update_date
         )
    OR     (     :p_item_status        = 'Updated Items'
         AND     msi.creation_date  != msi.last_update_date
         )
    OR     (     :p_item_status        NOT IN ( 'New Items'
                               , 'Updated Items'
                               )
         )
    

    This guess: p_item_status is not NULL.
    If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition to

    OR     ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items'
                                 , 'Updated Items'
                                 )
         )
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

Maybe you are looking for