1. IF syntax
IF expression then ... END IF;
For example:
Set Serverout ondeclare v_name varchar2: = ' &name '; begin if V_name= ' Kiki ' then dbms_output.put_ Line (' login successful '); End if;end;/--------execution results as follows-------Enter the value of name: Kiki 2: v_name varchar2: = ' &name '; new value 2: v_name varchar2: = ' kiki '; login successful
2. IF: ELSE Syntax:
IF Condition expression then
...
ELSE
...
END IF;
For example:
Set Serverout ondeclare v_name student.sname%type:= ' &name '; begin if V_name= ' Kiki ' then dbms_ Output.put_line (' Login successful! '); else dbms_output.put_line (' Login failed '); End if;end;/--------execution results as follows-------Enter the value of name: Kiki 2: v_name student.sname%type:= ' &name '; new value 2: v_name student.sname%type:= ' kiki '; Login failed
3. IF ... Elsif ... ELSE Nesting structure
IF condition expression then ... elsif conditional expression then ... ELSE ... END IF;
For example:
--1.if-else structure set Serverput on-open Oracle's own output method Dbms_outputdeclare-declaration v_name VARCHAR2: = ' &name ';-- Define variables that need to be entered manually V_password number: = ' &password '; Begin--Start if v_name= ' Kikiwen ' and v_password=123 then-- Conditional Judgment dbms_output.put_line (' login succeeded ');--output statement elsif v_name= ' Kiki ' and v_password=123 then dbms_output.put_ Line (' Login ' | | | v_name | | ' Account Success '); else dbms_output.put_line (' Login failed! ' | | V_name | | ' Incorrect account or password '); End if;end;--Finish/--------execution results as follows-------Enter a value for name: Kiki 2: v_name varchar2: = ' &name '; new value 2: v_name varchar2: = ' kiki '; input password value: 123 Original Value 2: v_name varchar2: = ' & Password '; new value 2: v_name varchar2 (20): = 123; login Kiki account Successful
Oracle If-else Conditional Judgment structure