The IF ELSE statement in Oracle executes different blocks of code based on conditions. It uses IF (condition) THEN...ELSE...END IF syntax, where condition is a Boolean expression, THEN code block executes when the condition is true, and ELSE code block executes when the condition is false. This statement can be nested, and the ELSE code block is optional.
Usage of IF ELSE in Oracle
The IF ELSE statement in Oracle is used to execute different statements based on specified conditions. code block. The syntax is as follows:
<code>IF (condition) THEN -- 如果条件为真,则执行此代码块 ELSE -- 如果条件为假,则执行此代码块 END IF;</code>
Usage:
Example:
<code class="oracle">DECLARE salary NUMBER; BEGIN salary := 5000; IF (salary > 6000) THEN -- 如果 salary 大于 6000,则执行此代码块 DBMS_OUTPUT.PUT_LINE('高薪员工'); ELSE -- 如果 salary 小于或等于 6000,则执行此代码块 DBMS_OUTPUT.PUT_LINE('普通员工'); END IF; END;</code>
Note:
<code class="oracle">IF (condition1) THEN -- 如果条件 1 为真,则执行此代码块 ELSIF (condition2) THEN -- 如果条件 2 为真,则执行此代码块 ELSE -- 如果条件 1 和条件 2 都为假,则执行此代码块 END IF;</code>
The above is the detailed content of How to use if else in oracle. For more information, please follow other related articles on the PHP Chinese website!