CASE in a WHERE clause: ORA-00905

Hello world
I try to use a BOX in a WHERE clause clause and I got the error ORA-00905: lack of keyword. Here is my code:

SELECT id_reserv,
Concat (name, Concat ('_', index)) as name,
Libelle,
num_lot,
resa_keyword1,
resa_keyword2,
resa_keyword3,
resa_keyword4,
date_creation,
comm_creation,
id_util,
assets,
id_env_act,
(SELECT connection of user u where u.id_util = r.id_util) AS nom_util,
(SELECT name e environment where e.id_env = r.id_env_act) AS nom_env,
(SELECT count (*) of rc reserv_comp where rc.id_reserv = r.id_reserv) AS nbComp,
(SELECT count (*) MC reserv_modif where mc.id_reserv = r.id_reserv) AS nbModif
BOOKING r
WHERE the r.nom NOT LIKE 'RESERV_LOT_ % '.
AND id_util = '1'
AND active = '1'
AND id_env_act > = '-1'.
AND the MATTER sansdemande
WHEN true THEN id_reserv not in some id_reserv from demande_livraison where id_env_dep > = '-1'.
ELSE id_reserv = id_reserv
END
AND name LIKE '% '.
ORDER BY date_creation;

I already looked at the CASE statement and it seems that the syntax is correct, so I don't know I can use in a WHERE clause.
Any help would be nice!

Andalusians

Hello

It should be something like this:

AND CASE
  WHEN 'false'='true' THEN (select id_reserv from demande_livraison where id_env_dep>='-1')
  ELSE id_reserv
     END = id_reserv 

The subquery must return a line

But I think that it is better to write your query in the form:

SELECT id_reserv,
     concat(nom,concat('_',indice)) as nom,
     libelle,
     num_lot,
     resa_keyword1,
     resa_keyword2,
     resa_keyword3,
     resa_keyword4,
     date_creation,
     comm_creation,
     id_util,
     actif,
     id_env_act,
     (SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util,
     (SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env,
     (SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp,
     (SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif
FROM reservation r
     WHERE r.nom NOT LIKE 'RESERV_LOT_%'
     AND id_util='1'
     AND actif='1'
     AND id_env_act>='-1'
     AND
                   (
                      (  'false'='true' and id_reserv not in (select id_reserv from demande_livraison where id_env_dep>='-1')
                      )
                      or
                      ( 'true'= 'true' and id_reserv=id_reserv
                      )
                   )
     AND nom LIKE '%'
ORDER BY date_creation;

This coding in SQL something as if a = b, then c, d also in the simplest form.

Herald tiomela
http://htendam.WordPress.com

Tags: Database

Similar Questions

  • Case with where clause - ORA-00920: invalid relational operator

    Hi all, when I try to run the following query, I get the following error...

    ORA-00920: invalid relational operator

    00920 00000 - "invalid relational operator.

    * Cause:

    * Action:

    Error on line: column 16: 5

    Anyone know what the problem with my request? Thanks in advance.

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    CASE WHERE period

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END as number 'months '.

    ORDER OF CONCAT (year, number 'months') / / DESC

    The problem is the number 'month' - you cannot give an "ACE" alias for an expression in a where clause clause.

    You have not really given any condition, that a set of translations of period in a number.

    Also, you didn't say what you're trying to do.

    Maybe you want to:

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    WHERE something

    ORDER OF CONCAT (year, period of the CASE

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END DESC)

    /

  • Display Variable for WHERE clause "ORA-06550, CLAUSE ought."

    Hi guys,.

    two questions
    1 can. a view cause variables such as:

    create view MYVIEW
    As
    MyName varchar (5) = bob

    Select * from mytable where name = MyName


    2. If so, why a simple select above cause
    the error 'ORA-06550, EXPECTED INTO clause'?

    Hello

    no direct way is not possible. There are solutions, see this thread on Asktom: [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:1448404423206] parameters discovers

    Herald tiomela
    http://htendam.WordPress.com

  • Case statement in where clause

    Hello

    I have to write the following query using the value of the l_var variable in the case statement

    How do I get there?


    Select col3

    of the test

    where col1 = "A".

    and the case

    When l_var = "Y' and col2 = 'B '.

    When l_var = 'n' and col2 = 'C '.

    end;

    In your expression

    case

    When l_var = 'Y' and col2 = 'B '.

    When l_var = ' only then col2 <> 'B '.

    end;

    you try to return a Boolean (True or False) value like 'then' value of the CASE statement.

    Values Boolean are not an Oracle SQL data type, you cannot use the true/false result of col2 = 'B' as an expression. This is why it does not work.

    It's even more simple as:

    Select col3

    of the test

    where col1 = "A".

    and ((l_var = «Y» et col2 = «B») or (l_var = ' no and col2 <> 'B'))

    If you really want a CASE statement then:

    Select col3

    of the test

    where col1 = "A".

    and the CASE WHEN l_var = 'Y', THEN CASE WHEN col2 = 'B', 1 ELSE 0 END

    WHEN l_var = ' no CASE THEN WHEN col2 <> 'B', 1 ELSE 0 END

    END = 1

  • Using the Case statement in Where clause with operator

    Hi all

    I'm doing the following work (this is just a simple version of what I'll eventually need):

    Sorry, I forgot how to use the code tags...

    and li. MAJOR_ACCT in case
    When: prompt = 'Energy' then ('9320906 ', ' 9321471')
    end


    Problem is that I get a missing closing parenthesis error.

    Wouldn't - that evaluate against a value(as below) it works fine:

    and li. MAJOR_ACCT in case
    When: prompt = 'Energy' then ('9320906')
    end


    Any thoughts? Is it possible to use a box (or decode) in an In clause with multiple values? I tried to use decode as well and get the same results.

    Thank you.

    Darren.

    What:

    and ( case
            when :prompt = 'Energy' and li.MAJOR_ACCT in ('9320906', '9321471') then 1
            when :prompt = 'Vehicle' and li.MAJOR_ACCT in ('9812180', '9812320')  then 1
            when :prompt = 'Meals' and li.MAJOR_ACCT in ('983120', '983452') then 1
          end
        ) = 1
    
  • Once again... Help... CASE in the WHERE clause...!

    Hi all

    I posted the question about CASES where the condition. It is one of the changes.

    The first condition was, if the Individual is 01 extraction then all the values of the table where the column of FLG = 'Y '. If the Individual is 02 and then extract all the values of the table where the column of FLG = ' no or NULL. Here, INDI is the setting.

    Select count (*) from cntl
    XYZ
    where NVL(FLG,'N') = decode(INDI,'01','Y','02','N');

    Now the chnages is, if the Individual is 01 and then extract all the values in the table where FLG colum = 'Y '. If the Individual is 02 and then extract all the values in the table, including ('Y', ' n, NULL). no need to put the filter of the FLG columns in which contion.

    It's not just...

    select count(*) into cntl
    from xyz
    where NVL(FLG,'N') = decode(INDI,'01','Y','02',NVL(FLG,'N'));
    

    Or shorter:

    select count(*) into cntl
    from xyz
    where NVL(FLG,'N') = decode(INDI,'01','Y',NVL(FLG,'N'));
    

    If you are happy for 01 retreat flg of Y and any other value fold everything.

    Published by: BluShadow on June 3, 2009 12:31

  • Help... CASE in the WHERE clause...!

    Hi all

    I need help in the following condition. I am passing the parameter say INDI. the value of INDI can be 01 or 02

    I am retriving count in a table. say,

    DECLARE
    CNTL varchar2 (5);
    BEGIN

    Select count (*) from cntl
    XYZ
    where FLG = CASE WHEN INDI = '01', then 'Y' END;

    dbms_output.put_line (cntl);
    END;

    the FLG column can contain the value "Y" or "n" or NULL. If I run the above code, it gives me a count for these lines where FLG = 'Y' for INDI 01. But if I spend INDI = 02, it should give me account for these lines that has FLG = ' not and NULL.

    If I say where FLG = CASE WHEN INDI = '01' and then 'Y' ELSE ' no END; then he'll give me an account for these lines that has FLG = ' don't, but here I want County to FLG = 'n' and FLG = NULL, if I spend INDI = 02

    I am not able to determine how I can achieve this...
    select count(*) into cntl
      from xyz
     where NVL(FLG,'N') = CASE WHEN INDI = '01' THEN 'Y'
                         WHEN INDI = '02' THEN 'N'
                     END;
    
  • using case when statement or decode unfavorable in where clause

    Hi the gems...

    I have a problem in the following query...
    I try to use when case statement in where clause of a select query.


    Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
    CR. Salary salary
    of customer_details cr
    where (case when ' > ' = ' > ' then ' cr.salary > 5000')
    When ' > ' = ' < ' then ' cr.salary < 5000'
    When ' > ' = '=' and then 'cr.salary = 5000'
    Another null
    (end);


    the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
    That is why, for the execution of the query, I put ' > ' in this place.

    If the original query will look like this (for reference):

    Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
    CR. Salary salary
    of customer_details cr
    where (case when variable = ' > ' then ' cr.salary > 5000')
    When the variable = ' < ' then ' cr.salary < 5000'
    When the variable = '=' and then 'cr.salary = 5000'
    Another null
    (end);


    so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
    If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
    If the user selects '=', then the filter will be 'where cr.salary = 5000 '.

    but I get the error "ORA 00920:invalid relational operator.

    Help, please... Thanks in advance...

    Hello

    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
           cr.salary                                      as salary
     from customer_details cr
    where (    v_variable = 'bigger'
           and cr.salary > 5000
          )
       or (    v_variable = 'less'
          and cr.salary < 5000
           )
       or (    v_variable = 'eq'
            and cr.salary = 5000
           )
    

    Published by: user6806750 on 22.12.2011 14:56
    For some reason that I can't write in sql "<', '="">", "=".

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

  • Need help with CASE When statement in a Where Clause

    So I have a SQL (simplified for this forum)

    Select t1.*
    from table1, table2 t2 t1
    where t1.field1 = t2.field1
    and when t1.field2 is null then trunc (sysdate) < = trunc (t1.date1 + 17)
    of another trunc (sydate) > = end of trunc (t2.date2 + t2.date3)

    I end up getting an error ORA-00905: lack of keyword

    I'm sure that I just got something here involved.

    You can not make the comparison within the statement underlying case like this. Assuming you have appropriate data types, something like this should work

    Select t1.*
    from table1 t1, table2 t2
    where t1.field1 = t2.field1
      and ((t1.field2 is null and
            trunc(sysdate) <= trunc(t1.date1 + 17)) or
           trunc(sydate) > = trunc(t2.date2 + t2.date3))
    

    John

  • Using a CASE statement in 'IN' where clause clause

    Hello

    I have a form that users see after they connect with a few items and they type or select values based on the element type. All reports in the application use these values of PAGE 1 in where clause to filter the lines.

    One of these question is "Quarter".  I have a group of radio buttons on the PAGE 1 on the P1_QTR point.

    I need to provide users a way to take the last 4, last 3, last 2 or current quarter and I need to dynamically build a clause WHERE the interactive report based on the selection in the form.

    I am trying to use the CASE as shown below and get the syntax error.

    AND QTR to (when BOX: P1_QTR = 'CURRENT' then ("T4"))

    When: P1_QTR = "LAST" then ("Q3")

    When: P1_QTR = 'LAST TWO' then ('Q3, "Q4")

    When: P1_QTR = 'LAST THREE' then ("Q2", "Q3,' T4 ')

    another ("T1", "T2", "Q3,' T4 ')

    END)

    How can I achieve this?

    Following a simple logic, try

    and QTR to

    (

    Select 'T4' double where: P1_QTR <> 'LAST '.

    Union of all the

    Select 'Q3' to double where: P1_QTR <> "in PROCESS".

    Union of all the

    Select "Q2" double where: P1_QTR not in ('CURRENT', 'LAST', "LAST TWO")

    Union of all the

    Select "Q1" double where: P1_QTR not in ('CURRENT', 'LAST', 'LAST TWO', 'THREE LATEST')

    )

  • Case instructions within a Where clause clause

    Hello group,

    I know this has been asked several times, but I do not enter simply to a tuition assistance box in a WHERE clause.  So I need help:

    My current WHERE the clause reads:

    A16. FULL_DATE between (SELECT (TRUNC (SysDate - 8)) From Dual) and (select (TRUNC (SysDate - 2)) double)

    However, I need to 'automate' a bit, based on the current time/day of the month.  I need my instruction box to say:

    (Case when to_char (sysdate-3, 'mm') <>to_char (sysdate, 'mm')

    then the a16. FULL_DATE (between SELECT (trunc (ADD_MONTHS ((LAST_DAY(SysDate-3)),-1)+1) and (SELECT (add_months (trunc(SysDate-2)-1)) of double)))

    Of another a16. FULL_DATE between (SELECT trunc (ADD_MONTHS ((LAST_DAY (SysDate)),-1)+1) From Dual) and (select (TRUNC (SysDate - 2)) From Dual)

    However, I have an error on "Else".  Can someone explain what is the problem and how to fix it?  I tried both 'then' and 'Else' syntax and both will run individually.  So I'm quite sure that he does not like my CASE statement in general.

    In advance, thank you for your help.

    Don

    I can't tell what your business logic, so here's a simple example of an instruction box in the where clause:

    SQL > select *.
    2 double
    3 where dummy = case when extracted (sysdate months) = 9 then 'W '.
    4 Once extracted (sysdate months) = 10 then 'X '.
    When 5 extract (month from sysdate) = 11 then 'Y '.
    6                      else 'Z'
    7                 end
    8;

    D
    -
    X

  • Where Clause condition - using CASES in which clause

    I generate data based on certain criteria of dates as below:


    I need to create a report based on the CLOSE_DATE COLUMN,

    If SYSDATE < 15 of the month can generate report on CLOSE_DATE between the 1st to the 15th of the current month
    If SYSDATE > 15th of the month and then generate report on CLOSE_DATE between the 16th of this month and the last day of the next month.

    I tried, but could not get to the query


    SELECT scheme_code, MODEL_NAME, close_date
    Plans OF
    WHERE)
    BOX WHEN to_number (to_char(close_date,'DD')) > 15
    THEN close_date BETWEEN trunc (trunc (SYSDATE, 'MM') + 15) AND last_day (add_months(SYSDATE,1))
    WHEN to_number (to_char(close_date,'DD')) < 15
    THEN close_date BETWEEN trunc(SYSDATE,'MM') AND trunc (trunc(SYSDATE,'MM') + 15)
    (END);

    where nearby date between the two cases when to_number (to_char (close_date, 'DD') > 15 then... else... end and case... when... then... else... end would be the right structure)

    in other words, you can use cases coming with each of these two values for him between the comparison. Do not use case to inject arbitrary clauses

  • Binds a parameter in WHERE clause throws error (ORA-00920)

    Good day to you all.  Hope everything goes well.

    Ok.  Here's the deal.  I am trying to bind a parameter in a where clause clause, but I continue to get the error invalid relational operator (ORA-00920).  It seems as if Oracle is looking for a correct syntax before you pass the variable (bind value).

    For example:

    SELECT LAST_NAME, FIRST_NAME FROM MYTABLE
    WHERE OBSOLETE IS NULL
    and :P_MY_BIND_VALUE
    

    What is the right way to get around this?

    Thanks for all your help!

    AquaNX4 wrote:

    Thank you for the reply.

    I use simple SQL.  The variable binding will be used in the APEX and an item that is based on a LOV with where condition stored there.  Make sense?

    Logic you want... doesn't have a sense of how you try to do.

    Bind variables are for the passage of the 'values' to a question, only not for the passage of the SQL statements or sections of objects such as the names of tables etc.  It is not a substitution string such as the use of '&' in SQL * more and should not be treated this way.

    If you could provide more details on exactly what you're trying to do (some data would help) then perhaps we could tell how best to go about this.

  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                                      ))
                            overdue_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained in the data definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)
    My modified code is the following,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)
    Both approaches have the same problem.
    The output is in EXCEL format. The modified query works very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth like

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )
    

    for overdue_flag, which has more then 'Y' values of "n".
    If overdue_flag that in ('Y', ' don't) then

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )
    

Maybe you are looking for

  • How disable/enable toolbars?

    I have too many active toolbars so I want to disable one of them sometimes.

  • No Haptics on the calendar of events?

    Is it just me or the world is something else also does not get haptic on calendar events? It appears on the screen, but it's not buzz my wrist, or me beep. Haptics are all lit, and other types of events "buzz me.» In the application of the watch, Cal

  • [Suggestion] Words of support?

    Hello everyone, I am a new user, so do not be angry with me. The Walkman player is great, I agree, but missing one thing I had without any addons on my old Nokia 500 (Symbian Belle!) - words of support. It would be great if you could upgrade the read

  • Pavillion dv7 laptop win7 freezes when you unplug ac pwr, need to start, will not start on the MTD

    I just bouht this laptop 2 months ago. It has been refurbished. Initially he had problems running and I have to hard start a few times to get it going.  I followed some instructions a previous forum solution sp44983 17/10/12, and it seemed to work. I

  • Resale of Windows 7 Home Premium upgrade.

    Is it legal to sell my copy of Windows 7 Home Premium Upgrade. It has been installed on a computer at a given time, but this computer is no longer in use due to a complete failure then the replacement. If it's legal, what information should I give th