sql - Using AND condition in decode -


i have scenario need check date , value determine result.

ex-

case when my_date > '10-01-2011' , my_value = 0 'do this' else  'do that' end 

i'm trying use in oracle sql query, wondering if there better approach logic rather using case statement; perhaps using decode or other oracle function.

case ansi sql standard conditional logic in sql. code therefore fine except string '10-01-2011' treating implicitly date. use ansi date literal format this:

case when my_date > date '2011-01-10' , my_value = 0   'do this' else    'do that' end 

decode oracle's proprietary solution conditional sql before case available. same logic expressed using decode this:

decode (my_value,         0, decode (sign (my_date - date '2011-01-10'),                     1,                     'do this',                    'do that'),         'do that') 

not elegant or readable it? uses sign function, returns 1 positive number, -1 negative, , 0 0.

note case can used in pl/sql whereas decode cannot.

-- works myvar := case when x=1 'a' else 'b' end; -- doesn't myvar := decode (x, 1, 'a', 'b'); 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -