Comparison of nulls in where clause

Hi team,

I want to select the data in the table based on some condition.
The problem is the data that I have to look in where clause is null or has a certain value.

The data are unknown so I can not use "is null" because if the data is not null then I have to use the '=' operator.
Please suggest a way to handle this situation, example below make the situation clearer for you.


I want data retirve that matches the current value of variable value1, value2, value3.

Name of the table:-DEMO(A,B,C)

A, B AND C

1 2 null

3 5 null

6 7 8


Select A, B, C of demo where A = 1 and B = value2 and c = value3;

Value1, value2, value3 are the variables that have some that can also be null.
If value1 or value2 value 3 having null that the above query does not work because I have to use to compare null values is null.

Please suggest me the query from right or procedure to deal with the current scenario.

Hello

DECODE treats NULL as a value, so you can do something like

SELECT     a, b, c
FROM     demo
WHERE     DECODE (a, value1, 'OK')     = 'OK'
AND     DECODE (b, value2, 'OK')     = 'OK'
AND     DECODE (C, value3, 'OK')     = 'OK'
;

Tags: Database

Similar Questions

  • Include nulls in where clause

    I have a question (which I use for Apex, but I think it's besides the point) that has a where clause clause.
    Select *
    from table1
    where Flag = :P24_Flag
    When: P24 is not specified, I want that she don't know where clause altogether, if flag is null or not.

    What is the most elegant way to do it?
    Select *
    from table1
    where (Flag = :P24_Flag OR :P24_Flag is null)
    

    ?

  • NULL columns in where clause

    Hello
    I use a table column in the where condition.
    For example. product_id <>1234 in where clause.
    and the query returns results which have id is not equal to 1234.

    My question is if the product id for a particular set (row) record is null, then only this record show upward in the result because it is not equal to 1234.

    In other words oracle made the comparison "<>null 1234 so retunr the record in the result set?

    Please advice. Thanks in advance.

    Hello

    No Oracle would not return columns with null values if this column is used in where clause with equal/not equal clause (= /! =)
    If there use null values in query

    where (product_id != 1234 or product_id is null)
    

    Concerning
    Anurag

  • How to set a null column in a where clause clause involving a statement box

    In oracle APEX, I a (selection list) element called: P32_STATUS. It contains two values of interest (for this discussion): 'Available' and 'checked '. In my report, I have a column called vc_status that contains two values: "Checkbox" and NULL. In my application I want to use a case statement in my where clause similar to the lines of

    where

    .

    .

    .

    AND (vc_status = CASE WHEN: P32_STATUS = "Checkbox" THEN : P32_STATUS )

    WHEN : P32_STATUS = 'Available' THEN NULL END)

    The 'box' filtering works but the filtering to try to vc_status the NULL value does not work. Can someone help me? Thank you!

    (P.S. My intuition says that there because I can not put vc_status = NULL, but I must say that vc_status IS NULL... However, I don't know how to do execution IS ZERO inside a CASE statement)

    Hello

    Your intuition is right...

    In Oracle NULL is a bit special:

    NULL = NULL is false

    NULL <> NULL is false

    Thus, instead of the parameter a NULL value in the CASE WHERE there is just set a value on the other side:

    NVL (vc_statut, 'Available') =: P32_STATUS

    That's all! Simple, clean and functional

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • How to solve where clause matter when it can have a value or be null.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Hello, I am trying to understand how a query in which I have a where clause clause that can be null or a value, that is to say:
    SELECT   supply,
                  duration,
                  count,
                  action
    FROM     MDR
    WHERE    (client     = gbl_client OR (group = gbl_group AND section = gbl_section ))
    AND      (prov_code   = gbl_prov_code );
    In the query, the gbl variables can have a value or be null, based on the results of a previous cursor. The problem is that if they have the value NULL, I don't get the correct results because where clause will have to be modified to be checked IS NULL instead of = gbl. Is it possible to do it by modifying select it?

    Hello

    Because these columns are all strings, the CONCAT method will work fine:

    SELECT     *
    FROM     mdr
    WHERE     '?' || grp       = '?' || glb_grp         -- GROUP is not a good column name
    AND     '?' || section    = '?' || glb_section
    AND     '?' || prov_code  = '?' || prov_code
    ;
    

    I think that the code is a little nicer with the '?' before the actual data. No matter whether it is before or after, just be consistent.

    Published by: Frank Kulash, January 25, 2011 15:59

  • where clause to see if they contain the null value

    So I've finalized my function but now am having some problems:

    the bl field (or the v_bl parameter) has null values in it. When I run the function using the "Select FH ('ACCESS', NULL, 8675309') From dual; I get a NULL return value because it uses the variable to compare with q.bl and you can not have q.bl = null in a Where clause.

    The main problem is when the parameters are passed, a line can have the same prob and site, but the bl might be different as null, which would give a different lname.


    In where clause I need to have something that will compare the parameter with the bl field. Sometimes it's null sometimes is not, but we need to find the line concerned. I made the "BOLD" in the question police

    Here are two possible lines in the data
    prob bl site lname
    ACCESS Smith 8675309 (null)
    54321 8675309 Johnson ACCESS

    so in theory, if the function is called with the parameters FH ('ACCESS', NULL, 8675306')
    He would return the lname: Smith

    and conversely FH ("ACCESS", "54321 ', 8675309") would return Johnson

    Here's the function

    create or replace
    Function FH
    (v_prob IN varchar2, v_bl IN varchar2, v_site IN varchar2)
    RETURN varchar2
    AS
    v_lname varchar2 (16);

    BEGIN

    S.Lname SELECT INTO v_lname
    Of
    request q
    JOIN THE
    s response
    On
    (q.order = s.order)

    WHERE
    q.BL = v_bl AND - where it is
    q.site = v_site AND
    q.prob = v_prob AND
    s.Lname IS NOT NULL;

    RETURN v_lname;
    END;



    -When I run the FH ('ACCESS', NULL,' 86753) function, it returns an empty value and not the family name

    Published by: user11210446 on May 28, 2009 17:03

    Published by: user11210446 on May 28, 2009 17:03

    user11210446 wrote:
    If v_bl is Null in the where clause it would even say q.bl = Null which will not work.

    Matches the NULL value
    (1) either you have to say-> q.bl IS NULL
    OR
    (2) WHERE the NVL (q.bl-99) = NVL (v_bl-99) - this will be true if q.bl and v_bl both are NULL
    NULL = NULL evaluates to TRUE, so you use NVL

    SS@XE > select * from dual where null = null ;
    
    no rows selected
    
    SS@XE > select * from dual where null is null ;
    
    D
    -
    X
    
    SS@XE > select * from dual where NVL(null,-1) = NVL(null,-1) ;
    
    D
    -
    X
    

    SS

  • T/t with the WHERE clause using a list breaks

    Hello, all,.

    I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking.  I don't know what I'm doing wrong.

    For some pseudo-code, do I have a complete query of a database called 'people '.  A list of values for the t/t with the first query; the second query is my t/t:

    <cfquery name="getDIR" datasource="#request.THISDSN#">
        SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />)
    </cfquery>
    
    <cfquery name="people" database="people">
        SELECT colA, colB, colC, colD
        FROM people
        WHERE 1=1
            AND (
                div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />)
                )
    </cfquery>
    
    
    

    I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".»  Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »

    Can support _not_ QoQ lists of WHERE clauses?

    V/r,

    ^_^

    SMH - so much... I just found.

    I forgot to give the lists in the second query bracket.


    (The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)

    * headdesk * headdesk * headdesk * headdesk *.

    V/r,

    ^_^

  • How can I extract a substring in WHERE Clause &lt; CFQUERY &gt;?

    Is it possible to extract a substring in the WHERE clause of either < CFQUERY > or in a query of queries?  I try to use the following query to find all e-mail addresses with the domain "comcast.net" (i.e., everything that follows the '@' in the email address).  I ask an MS-Access database table.

    < cfquery name='test' datasource='membership'>
    SELECT Email_address
    OF tblMembers
    WHERE the MID (email_address, INSTR (email_address, ' @') + 1) = "comcast.net"
    < / cfquery >


    If I try this as a query, I get the error message "[Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] data type incompatible in criteria expression."


    If I try it as a t/t, I get the error message " " Met 'MID (e-mail1.,. Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition,'.

    I would be very grateful for any help on finding something that works!  Thanks for your help!


    You couldn't do a LIKE in where clause instead:

    SELECT Email_address

    OF tblMembers

    WHERE email_address LIKE ' %@comcast.net'

    You should get the addresses you're looking for.

    -Carl V.

  • TO_CHAR in where clause

    Hello

    Here's my query below. I added a to_char dates in my paintings (expiry_dstamp) but now my request does not take the "superior to" in my where clause into consideration.

    Could someone ' a please inform me on what I should do now with my where clause.
    select *
    from
    
    (select distinct sku_id pfs, location_id pfl, to_char(expiry_dstamp, 'DD-Mon-YYYY') pfexd
    from inventory
    where pick_face = 'F') pf,
    
    (select distinct i.sku_id npfs, i.location_id npfl, to_char(i.expiry_dstamp, 'DD-Mon-YYYY') npfexd
    from inventory i, location l
    where i.pick_face is null
    and lock_code is null
    and i.location_id = l.location_id
    and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf
    
    where pf.pfexd > npf.npfexd
    and npf.npfs = pf.pfs
    order by pf.pfl
    Thank you

    SM

    It is the taking into account, but now you're string comparison no dates...

    Try this

    select to_Char (pfexd, 'dd-mon-yyyy')
    , to_char (npfexd, 'dd-mon-yyyy')
    from
    
    (select distinct sku_id pfs, location_id pfl, expiry_dstamp pfexd
    from inventory
    where pick_face = 'F') pf,
    
    (select distinct i.sku_id npfs, i.location_id npfl, i.expiry_dstamp npfexd
    from inventory i, location l
    where i.pick_face is null
    and lock_code is null
    and i.location_id = l.location_id
    and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf
    
    where pf.pfexd > npf.npfexd
    and npf.npfs = pf.pfs
    order by pf.pfl
    

    not tested

    Published by: Alex Nuijten on January 7, 2010 17:45

    Published by: Alex Nuijten on January 7, 2010 17:46

  • Complex Inner Join and outer subquery where clause to join internal?

    The DDL for this post was too big and I had to put on my site:
    http://www.harbortownsolutions.com/DDLForDORTable.txt

    My goal is to create a report of sales data for 116 stores containing daily sales and count of comments in recent years. My challenge is that I am pulling data from the same table, but with different dates to get data from last year and the week in data from date of last year.


    The dates used for reports are:

    SalesDate = 06/04/2009
    SalesDateForLastYear = 2008-06-05
    SalesDateBeginningOfWeek = 01/06/2009
    SalesDateBginningOFWeekLastYear = 2008-06-02

    PSEUDOQUERYS:
    ---======= DOLLAR VARIANCE = You Said you have $100 worth of meat(inventory) but you only have $50 worth of meat
    SELECT 
        BUSI_DATE as BusinessDate, 
        ORACLE_KEY as StoreID,
        FIELD1  as Sales,
        FIELD2  as GuestCount,
        FIELD3  as DollarVariance,
        FIELD4  as Cars
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores); 
    -======= ONLY Guest count and Sales are needed in comparisons against last year    
    ---======    Last YEar dates = corresponding dates for this year ie Tuesday of this 
    week matched to Tuesday of last year (except for leap year)
    SELECT 
        ORACLE_KEY as StoreID
        FIELD1  as SalesLastYear
        FIELD2  as GuestCountLastYear   
    FROM MYDAILYTOTALS
    WHERE Busi_date = SalesDateForLastYear 
       AND ORACLE_KEY IN (SELECT StoreID From MyStores);
           
    
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSales
        SUM(FIELD2)  as WeekToDateGuestCount  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeek and SalesDate
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY 
       --=======  
    SELECT 
        ORACLE_KEY as StoreID
        SUM(FIELD1)  as WeekToDateSalesLastYear
        SUM(FIELD2)  as WeekToDateGuestCountLastYear  
    FROM MYDAILYTOTALS
    WHERE Busi_date BETWEEN SalesDateBeginningOfWeekLastYear and SalesDateLastYear
       AND ORACLE_KEY IN (SELECT StoreID From MyStores) 
    GROUP BY ORACLE_KEY   
    Question: Since they all use the same store of nbrs, I specify on each request? Can't I just specify only once on outer query Where clause?

    Also, how would fit the following of HOEK script:
    See how I put 1 field based on another field value

    He reads a record for each store of 116 stores in the database. There are 2 situations that have been addressed by Hoeks code:
    For each of the 116 stores in the store table, there must be 1 and only
    registration of 1 stock to match the record of MyStoreTotals. However, sometimes there is no record of inventory.
    and sometimes there will be 2 (in a case where a manager of database updates)
    After daily treatment) files. If so, the record with Is_posted = 1
    is the one that should be included in the query. The following text accomplishes this:
    -chr (39) is the single quote
     Select StoreId, 
             DollarVariance 
      from   (select store.storeid, 
                       case
                              when inv.storeid is null then 'None'
                              when inv.is_posted = 0 then 'NP'
                              else chr(39)||inv.total_dol_var||chr(39)
                        end as DollarVariance, 
                        row_number() over (partition by store.storeid order by inv.is_posted desc) rn  
                   from  myInven inv 
                   right outer join mystores  store
                                  on store.storeid = inv.fk_str_main_id
                                  and inv.busi_date = to_date(SalesDate, 'dd-mon-yyyy'))
          where rn = 1;      
    Can I put this request on the place where clause of the outer to query I put on a JOIN clause?

    So I guess that's why you used the MAX.

    That is right.
    I used CASES to identify and complete the necessary columns since the first set of results (WITH).
    So then I more or less "swivels somehow" lines of this result set to the columns, each store will appear once the most.

  • where clause to query the hierarchy in the tree Apex area does not

    Hi all

    I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.

    I'm trying to populate Tree Menu with data specific to a user successfully logged on.

    (A) table created as HR2. TREE_MENU

    menu_name varchar2 (50).

    number of menu_parent

    number of menu_child

    menu_id varchar2 (12),

    menu_path varchar2 (100),

    number of user_no

    (B) SQL statement for the tree in the Apex region

    Select case when connect_by_isleaf = 1 then 0

    When level = 1 then 1

    else                           -1

    end the status,

    level,

    'Menu_name' as the title,

    NULL as an icon,

    "MENU_CHILD" as a value.

    NULL as ToolTip,

    NULL as link

    to HR2. "" TREE_MENU ".

    -WHERE USER_NO =: P_USERNO

    Start with 'MENU_CHILD' is null

    connect prior "MENU_PARENT" = "MENU_CHILD."

    brothers and sisters of order by 'MENU_ID '.

    Note: also used static value where clause but is not workd.

    that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.

    Help, please.

    Kind regards.

    If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "MENU_NAME" as title,
           null as icon,
           "MENU_CHILD" as value,
           null as tooltip,
           null as link
    from HR2."TREE_MENU"
    start with "MENU_CHILD" is null
    connect by
        prior "MENU_PARENT" = "MENU_CHILD"
        and "USER_NO" = 7
    order siblings by "MENU_ID"
    

    Concerning

    Mahmoud

  • Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition

    Hello

    I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:

    AND HOST_NAME IN

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER

    ("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")

    END

    )

    I get the following:

    ORA-00907: lack of right parenthesis

    00907 00000 - "lack the right parenthesis.

    But there is no missing parentheses!

    If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...

    I also tried:

    AND

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE

    HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")

    END

    )

    the error I get is:

    ORA-00905: lack of keyword

    00905 00000 - 'lack the key word'

    What keyword miss me?

    Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8

    Hello

    c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:

    It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)

    I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem.  Is it possible to re - write this?

    ...

    IF only works in PL/SQL.  It does not in SQL, even if that SQL is embedded in PL/SQL.

    There are many ways to re - write the condition.  And here's one:

    AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    )

    OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND TO_DATE (: StopDate, "MON-DD-YYYY")<  to_date="" ('dec-22-2015', ="">

    )

    )

    If: StopDate can be NULL, it must be a bit more complicated.

    You can also use nested, such as CASE expressions

    AND THE CASE

    WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    WHILE CASE

    WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND THEN 'OK '.

    END

    OTHER CASES

    WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND THEN 'OK '.

    END

    END = 'OK '.

    I wonder if this in your application is the best way, however.  If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table.  If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used.  Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.

  • several instructions box in where clause

    Hello

    I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.

    where

    i.compute_zone =

    case

    When: P14_zone is NOT NULL

    then: P14_zone

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_2 is NOT NULL

    then: P14_zone_2

    other: P14_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_3 is NOT NULL

    then: P14_zone_3

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_4 is NOT NULL

    then: P14_zone_4

    of other i.compute_zone

    end

    any suggestions?

    Thank you

    MICAH

    Hi, Micah,

    User12611868-Oracle wrote:

    Hello

    I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.

    where

    i.compute_zone =

    case

    When: P14_zone is NOT NULL

    then: P14_zone

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_2 is NOT NULL

    then: P14_zone_2

    other: P14_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_3 is NOT NULL

    then: P14_zone_3

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_4 is NOT NULL

    then: P14_zone_4

    of other i.compute_zone

    end

    any suggestions?

    Thank you

    MICAH

    How get the desired results of your data depends on the desired results and your data.  What do you do?  (I can't tell just by looking at the aat code that do not do).  After CREATE TABLE and INSERT statements for some sample data and a couple of sets of parameters (variables such as p14_zone) and the exact results that your choices in each set of parameters, given the same sample data.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

    CASE expressions are generally not useful in a WHERE clause.  CASE expressions are a convenient way to IF-THEN-ELSE logic of the places where you can't do anything other than (the SELECT clause), but WHERE the clauses allow IF-THEN-ELSE logic in any case

    Maybe you want something like

    WHERE MERGE (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4) IS NULL

    OR IN i.compute_zone (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4)

    It returns TRUE if all 4 parameters are set to NULL.  If 1 or more of them are not NULL, then it will return TRUE if i.compute_zone is equal to one of them.

  • Using decode in where clause

    Hello

    I need to use decode condition in where clause in such a way that if the respective column is null then consider the corresponding column

    for example

    Fee_dateFee_refund_date
    10 OCTOBER 05
    12 NOVEMBER 05
    11 JANUARY 06
    16 FEBRUARY 06

    I have a request in place as below where p_fee_flag will be passed as either FEES or set to null, I check another condition as if p_fee_flag is null then fee_date must be set to null when comparing fee_refund_date between TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE

    SELECT 1

    BUCKET BKT

    WHERE DECODE (P_FEE_FLAG, 'FEES', TRUNC(FS.) FEE_DATE), TRUNC (FS. FEE_REFUND_DATE))

    BETWEEN TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE)

    944524 wrote:

    Hello Alberto,.

    Thank you that's what I ask but is it possible to verify the condition even using decode

    Yes, it is possible, but why?

    Just replace the query in this way:

    select *
      from fee_table f
    where exists(select 1
                    from bucket b
                  where decode(:p_fee_flag, 'FEE', f.fee_date, f.fee_refund_date) between b.act_start_date and b.act_end_date)
      and decode(:p_fee_flag, 'FEE', null, f.fee_date) is null;
    

    Kind regards.

    Alberto

Maybe you are looking for