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 15 loop
4. dbms_output.put_line(v_id);
5. end loop;
6. end;
关于Oracle数据库各类控制语句的使用就介绍到这里了,希望本次的介绍能够对您有所收获!
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 15 loop
4. dbms_output.put_line(v_id);
5. end loop;
6. end;
关于Oracle数据库各类控制语句的使用就介绍到这里了,希望本次的介绍能够对您有所收获!
转载于:https://blog.51cto.com/xuanjicto/725259