Oracle If-else Conditional Judgment structure

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.