Detailed introduction to the use of various control statements in Oracle databases

Source: Internet
Author: User

Oracle DatabaseVariousControl statementThe usage is what we will introduce in this article, including some logical control statements, the use of Case when, the use of While, and the use of, next we will introduce this part one by one, hoping to help you.

Logical control statements in Oracle

 
 
  1. If elsif else end if    
  2. set serverout on;    
  3. declare per_dep_count number;    
  4. begin    
  5. select count(*) into per_dep_count from emp;    
  6. if per_dep_count>0 then    
  7. dbms_output.put_line('Big Than 0');    
  8. elsif per_dep_count>5 then <span style="font-size:24px;color:#ff0000;"><strong>--elsif not elseif!!!!     
  9. </strong></span>                dbms_output.put_line('Big Than 5');    
  10. else    
  11. dbms_output.put_line('En?');    
  12. end if;    
  13. end;  

Use Case when in two ways

1)

 
 
  1. declare per_dep_count number;    
  2. begin    
  3. select count(*) into per_dep_count from emp;    
  4. case per_dep_count    
  5. when 1 then    
  6. dbms_output.put_line('1');    
  7. when 2 then    
  8. dbms_output.put_line('2');    
  9. else    
  10. dbms_output.put_line('else');    
  11. end case;    
  12. end;   

2)

 
 
  1. declare per_dep_count number;    
  2. begin    
  3. select count(*) into per_dep_count from emp;    
  4. case     
  5. when per_dep_count=1 then    
  6. dbms_output.put_line('1');    
  7. when per_dep_count=2 then    
  8. dbms_output.put_line('2');    
  9. else    
  10. dbms_output.put_line('else');    
  11. end case;    
  12. end;   

While usage

 
 
  1. declare v_id number:=0;    
  2. begin    
  3. while v_id<5 loop    
  4. v_idv_id:=v_id+1;    
  5. dbms_output.put_line(v_id);    
  6. end loop;    
  7. end;   

For

 
 
  1. declare v_id number:=0;    
  2. begin    
  3. for v_id in 1..5 loop    
  4. dbms_output.put_line(v_id);    
  5. end loop;    
  6. end;  

The usage of various control statements in the Oracle database is introduced here. I hope this introduction will be helpful to you!

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.