Oracle 5.0 Reference Manual page 903

Table of Contents

Advertisement

Name
[883]
IF()
[884]
IFNULL()
[884]
NULLIF()
CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN
result ...] [ELSE result] END
CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE
[883]
result] END
The first version returns the
the result for the first condition that is true. If there was no matching result value, the result after
is returned, or
ELSE
mysql>
SELECT CASE 1 WHEN 1 THEN 'one'
->
WHEN 2 THEN 'two' ELSE 'more' END;
-> 'one'
mysql>
SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
-> 'true'
mysql>
SELECT CASE BINARY 'B'
->
WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
-> NULL
The return type of a
CASE
but also depends on the context in which it is used. If used in a string context, the result is returned
as a string. If used in a numeric context, the result is returned as a decimal, real, or integer value.
Note
The syntax of the
that of the SQL
for use inside stored programs. The
NULL
IF(expr1,expr2,expr3)
If
is
TRUE (expr1 <> 0
expr1
it returns expr3.
IF()
is used.
mysql>
SELECT IF(1>2,2,3);
-> 3
mysql>
SELECT IF(1<2,'yes','no');
-> 'yes'
mysql>
SELECT IF(STRCMP('test','test1'),'no','yes');
-> 'no'
If only one of
expr2
type of the
non-NULL
The default return type of
calculated as follows.
Expression
or
returns a string
expr2
expr3
or
returns a floating-point value
expr2
expr3
or
returns an integer
expr2
expr3
If
and
expr2
expr3
Control Flow Functions
Description
If/else construct
Null if/else construct
Return NULL if expr1 = expr2
[883]
where value=compare_value. The second version returns
result
if there is no
NULL
ELSE
[883]
expression is the compatible aggregated type of all return values,
[883]
CASE
statement described in
CASE
clause, and it is terminated with
[883]
and
expr1 <>
[883]
returns a numeric or string value, depending on the context in which it
or
is explicitly NULL, the result type of the
expr3
expression.
[883]
(which may matter when it is stored into a temporary table) is
IF()
are both strings, the result is case sensitive if either string is case sensitive.
883
part.
expression shown here differs slightly from
Section 13.6.5.1,
statement cannot have an
CASE
END CASE
NULL) then
[883]
IF()
"CASE
Syntax",
ELSE
instead of END.
returns expr2; otherwise
[883]
function is the
IF()
Return Value
string
floating-point
integer

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents