在PL/SQL中,IF-THEN-ELSIF語(yǔ)句允許在多種選擇之間進(jìn)行選擇。IF-THEN語(yǔ)句后面可以有一個(gè)可選的ELSIF ... ELSE語(yǔ)句。 ELSIF子句可用于添加附加條件。
使用IF-THEN-ELSIF語(yǔ)句時(shí)需要注意幾點(diǎn)。
PL/SQL編程語(yǔ)言中的IF-THEN-ELSIF語(yǔ)句的語(yǔ)法是 -
IF(boolean_expression 1)THEN
S1; -- Executes when the boolean expression 1 is true
ELSIF( boolean_expression 2) THEN
S2; -- Executes when the boolean expression 2 is true
ELSIF( boolean_expression 3) THEN
S3; -- Executes when the boolean expression 3 is true
ELSE
S4; -- executes when the none of the above condition is true
END IF;
SQL
參考以下示例代碼 -
SET SERVEROUTPUT ON SIZE 1000000;
DECLARE
a number(3) := 100;
BEGIN
IF ( a = 10 ) THEN
dbms_output.put_line('Value of a is 10' );
ELSIF ( a = 20 ) THEN
dbms_output.put_line('Value of a is 20' );
ELSIF ( a = 30 ) THEN
dbms_output.put_line('Value of a is 30' );
ELSE
dbms_output.put_line('None of the values is matching');
END IF;
dbms_output.put_line('Exact value of a is: '|| a );
END;
/
SQL
當(dāng)上述代碼在SQL提示符下執(zhí)行時(shí),它會(huì)產(chǎn)生以下結(jié)果 -
更多建議: