注册 | 登录 |
地方论坛门户及新闻和人才网址大全

详解Oracle数据库各类控制语句的使用

时间:2021-07-21人气:-


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

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

Oracle 中逻辑控制语句

  1. Ifelsifelseendifsetserverouton;
  2. declareper_dep_countnumber;begin
  3. selectcount(*)intoper_dep_countfromemp;ifper_dep_count>0then
  4. dbms_output.put_line('BigThan0');elsifper_dep_count>5then<spanstyle="font-size:24px;color:#ff0000;"><strong>--elsifnotelseif!!!!
  5. </strong></span>dbms_output.put_line('BigThan5');else
  6. dbms_output.put_line('En?');endif;
  7. end;

Case when 的使用的两种方式 :

第一种使用方式

  1. declareper_dep_countnumber;begin
  2. selectcount(*)intoper_dep_countfromemp;caseper_dep_count
  3. when1thendbms_output.put_line('1');
  4. when2thendbms_output.put_line('2');
  5. elsedbms_output.put_line('else');
  6. endcase;end;

第二种使用方式

  1. declareper_dep_countnumber;begin
  2. selectcount(*)intoper_dep_countfromemp;case
  3. whenper_dep_count=1thendbms_output.put_line('1');
  4. whenper_dep_count=2thendbms_output.put_line('2');
  5. elsedbms_output.put_line('else');
  6. endcase;end;

While 的使用

  1. declarev_idnumber:=0;begin
  2. whilev_id<5loopv_idv_id:=v_id+1;
  3. dbms_output.put_line(v_id);endloop;
  4. end;

For的使用

  1. declarev_idnumber:=0;begin
  2. forv_idin1..5loopdbms_output.put_line(v_id);
  3. endloop;end;

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


上篇:linux自动运行rman增量备份脚本

下篇:两种oracle创建字段自增长的实现方式