In Oracle PL/SQL, IF condition is used to perform a logical check on certain values. If the condition is TRUE or FALSE then executes the statements followed by that condition. In this blog post, I am giving an Oracle IF Condition example with it's syntax information.
Syntax
IF boolean_condition THEN -- statements to execute ELSIF boolean_condition THEN -- statements to execute ELSE -- statements to execute END IF;
Oracle IF Condition Example
In the following example, the PL/SQL program will check the variable a value using IF Condition, that if it is NULL or is between 1 to 9 or is greater than 9 and then whichever the condition is true, will print on the screen.
SET SERVEROUTPUT ON;
DECLARE
a NUMBER;
BEGIN
a := 10;
IF a IS NULL
THEN
DBMS_OUTPUT.put_line ('a is null.');
ELSIF a > 0 AND a < 10
THEN
DBMS_OUTPUT.put_line ('a is between 1 to 9.');
ELSE
DBMS_OUTPUT.put_line ('a is greater than 9.');
END IF;
END;
/Output:
a is greater than 9. PL/SQL procedure successfully completed.
See also:
- Oracle FOR LOOP REVERSE Example
- Oracle WHILE LOOP Example
- Oracle Concatenate String and Number Example
