Oracle数据库各类控制语句的使用详细介绍

数据库 Oracle
本文我们主要介绍了Oracle数据库中各种控制语句的使用,包括逻辑控制语句、Case when的使用、While的使用以及For的使用等,希望本次的介绍能够对您有所收获!

Oracle数据库各类控制语句的使用是本文我们主要要介绍的内容,包括一些逻辑控制语句、Case when的使用、While的使用以及For的使用等等,接下来我们就开始一一介绍这部分内容,希望能够对您有所帮助。

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;  

 

Case when 的使用的两种方式  

(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 的使用  

 

  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;  

 

关于Oracle数据库各类控制语句的使用就介绍到这里了,希望本次的介绍能够对您有所收获!

【编辑推荐】

  1. 如何用SAS宏实现Oracle中的decode函数?
  2. Oracle数据库日期范围查询的两种实现方式
  3. Oracle数据库只读模式的CACHE BUFFERS CHAINS测试
  4. Oracle 10g数据库中UNDO_RETENTION参数的使用详解
  5. Oracle 10g默认归档路径在闪回区的2G空间大小限制问题
责任编辑:赵鹏 来源: CSDN博客
相关推荐

2010-04-02 12:23:30

Oracle数据库

2011-08-05 13:17:34

Oracle数据库闪回个性

2011-07-27 11:08:49

Oracle数据库EM Console重

2010-04-15 15:42:11

Oracle数据库

2011-08-11 16:29:49

Oracle数据库AWRASH

2011-05-26 13:29:30

ORACLE数据库升级

2010-04-15 13:01:25

Oracel数据库

2015-10-28 14:45:35

ORACLE AIO异步IO

2015-10-28 17:39:04

ORACLE AIO异步IO

2011-05-26 15:27:08

Oracle数据库

2011-03-21 13:21:23

数据库开发规范

2010-05-07 17:39:02

Oracle数据库性能

2010-04-23 14:32:01

Oracle数据库

2010-04-20 11:41:55

Oracle数据库

2010-04-23 16:05:50

Oracle数据库

2011-05-17 13:43:23

Oracle数据库

2010-04-07 09:31:02

Oracle数据库

2010-03-18 09:28:14

Oracle数据库迁移

2009-08-24 18:09:13

C#调用Oracle数

2011-08-02 18:38:19

MySQLINI文件
点赞
收藏

51CTO技术栈公众号