IF 语句根据一个布尔表达式的值决定是执行还是跳过一序列的语句。语法格式如下:
IF boolean_expression THEN statement [, statement ]
[ ELSIF boolean_expression THEN statement [, statement ] ]...
[ ELSE statement [, statement ] ]
END IF;
示例:使用 IF 语句
delimiter /
CREATE OR REPLACE PROCEDURE sp_guess(p_value IN number)
IS
BEGIN
IF p_value IS NULL THEN
dbms_output.put_line('The value is NULL!');
ELSIF (p_value < 0) THEN
dbms_output.put_line('The value is a negative number. ');
ELSE
dbms_output.put_line('The value is a positive number. ');
END IF;
END;
/
delimiter ;
obclient>
obclient> set serveroutput on;
Query OK, 0 rows affected (0.00 sec)
obclient> call sp_guess(2020);
Query OK, 0 rows affected (0.03 sec)
The value is a positive number.
obclient> call sp_guess(-2000);
Query OK, 0 rows affected (0.00 sec)
The value is a negative number.
obclient>