Detailed explanation of the use of various control statements in Oracle database _oracle

Source: Internet
Author: User
Tags oracle database

The use of various control statements in Oracle database is the main content we want to introduce in this article, including some logic control statements, the use of cases, while and for use, and so on, we begin to introduce this part of the content, hope to be helpful to you.

Logical control statements in Oracle

If elsif else End if  
set serverout on;  
declare per_dep_count number;  
Begin  
Select COUNT (*) into the per_dep_count from EMP;  
If Per_dep_count>0 then  
dbms_output.put_line (' big Than 0 ');  
elsif per_dep_count>5 then <span style= "Font-size:24px;color: #ff0000;" ><strong>--elsif NOT ElseIf!!!!   
</strong></span>        dbms_output.put_line (' Big Than 5 ');  
else  
dbms_output.put_line (' En? ');  
End If;  

The two ways in which case is used:

The first way of using

declare per_dep_count number;  
Begin  
Select COUNT (*) into the per_dep_count from EMP;  
Case Per_dep_count when  
1 then  
dbms_output.put_line (' 1 ');  
When 2 then  
dbms_output.put_line (' 2 ');  
else  
dbms_output.put_line (' Else ');  
End case;  
End  

The second way of using

declare per_dep_count number;  
Begin  
Select COUNT (*) into the per_dep_count from EMP;  
Case when   
per_dep_count=1 then  
dbms_output.put_line (' 1 ');  
When per_dep_count=2 then  
dbms_output.put_line (' 2 ');  
else  
dbms_output.put_line (' Else ');  
End case;  
End  

the use of while

declare v_id number:=0;  
Begin while  
v_id<5 loop  
v_idv_id:=v_id+1;  
Dbms_output.put_line (v_id);  
End Loop;  
End  

For use

declare v_id number:=0;  
Begin for  
v_id in 1..5 loop  
dbms_output.put_line (v_id);  
End Loop;  
End 

About the use of various types of Oracle database control statements are introduced here, I hope this introduction can be harvested for you!

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.