Oracle condition branch statement example

Source: Internet
Author: User
Tags oracle cursor

Oracle conditional branch statements are frequently used. The following describes the syntax of Oracle conditional branch statements in detail. If you are interested in this, take a look.

Oracle condition branch statements are used to select the operation to be executed based on specific conditions. PL/SQL provides three Oracle condition branch statements: if-then, if-then-else, if-then-elsif.

Syntax:

 
 
  1. if conditions then  
  2. statements;  
  3. [elseif conditions then   
  4. statements;]  
  5. [else   
  6. statements;]  
  7. end if;   

1. if-then example

It is used to perform a single condition judgment. If a specific condition is met, the corresponding operation is performed. If the condition is not met, the condition branch statement is exited.

 
 
  1. Declare
  2. V_count number;
  3. Begin
  4. Select count (*) into v_count from cip_temps;
  5. If (v_count> 0) then
  6. Dbms_output.put_line ('v _ cont value: '| v_count );
  7. End if;
  8. End;
  9. /

2. if-then-else example
It is used to perform dual-condition judgment. If a specific condition is met, one group of operations is performed. If the condition is not met, another group of operations is performed.

 
 
  1. Declare
  2. V_count number;
  3. Begin
  4. Select count (*) into v_count from cip_temps;
  5. If (v_count> 11) then
  6. Dbms_output.put_line ('v _ cont value: '| v_count );
  7. Else
  8. Dbms_output.put_line ('v _ count value: '| v_count );
  9. End if;
  10. End;
  11. /

3. if-then-elsif example
It is used to perform multi-condition judgment. If condition 1 is met, the first group of operations will be executed. If condition 2 is met, the second group of operations will be executed, and so on, if none of the conditions are met, the operation that does not meet the conditions is executed.

 
 
  1. Declare
  2. V_count number;
  3. Begin
  4. Select count (*) into v_count from cip_temps;
  5. If (v_count> 10) then
  6. Dbms_output.put_line ('If operation ___ v_cont value: '| v_count );
  7. Elsif (v_count = 10) then
  8. Dbms_output.put_line ('elsif operator ____ v_count value: '| v_count );
  9. Else
  10. Dbms_output.put_line ('else operator ____ v_cout value: '| v_count );
  11. End if;
  12. End;
  13. /

Oracle authorization statement

Statement of Oracle cyclic statements

Introduction to Oracle user creation syntax

Oracle Default User Password Problems

Common Oracle cursor attributes

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.