IF CASE

IF

IF variable = TRUE THEN
DBMS_OUTPUT.PUT_LINE('true');
ELSIF variable = FALSE THEN
DBMS_OUTPUT.PUT_LINE('false');
ELSE
DBMS_OUTPUT.PUT_LINE('neiter true nor false, NULL most probably');
END IF;

CASE

Type 1: where we choose a variable in advance

CASE variable
WHEN TRUE THEN
DBMS_OUTPUT.PUT_LINE('true');
WHEN FALSE THEN
DBMS_OUTPUT.PUT_LINE('false');
ELSE
DBMS_OUTPUT.PUT_LINE('neither true nor false, NULL most probably');
END CASE;

Type 2: we determine the variable for every case

CASE
WHEN variable1 = TRUE THEN
DBMS_OUTPUT.PUT_LINE(‘variable 1 is true’);
WHEN variable2 = TRUE THEN
DBMS_OUTPUT.PUT_LINE(‘variable 2 is true’);
WHEN variable1 = FALSE THEN
DBMS_OUTPUT.PUT_LINE(‘variable 1 is false’);
WHEN variable2 = FALSE THEN
DBMS_OUTPUT.PUT_LINE(‘variable 2 is false’);
ELSE
DBMS_OUTPUT.PUT_LINE(‘variables 1 and 2 are neither true nor false’);
END CASE;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: