oracle之存储过程6- if、for、游标使用
2017-03-13 15:26
495 查看
1、if判断语句使用
create or replace procedure test01 is
V_TEST number(10):=1;
begin
if V_TEST = 1 then
dbms_output.put_line('1----');
end if;
if V_TEST = 1 then
dbms_output.put_line('1----');
else if V_TEST = 2 then
dbms_output.put_line('2----');
else if V_TEST = 3 then
dbms_output.put_line('3----');
end if;
end if;
end if;
end test01;
2、for语句使用
Sql代码
create or replace procedure test01 is
begin
For x in 0 .. 10 LOOP
dbms_output.put_line(x||'----');
end LOOP;
end test01;
3、游标使用
游标的使用 Oracle 中Cursor 是非常有用的,用于遍历临时表中的查询结果。
将emp表中"ename"和"deptno"查询出,存放到cusor_01游标中。for循环迭代游标集合。每次迭代的结果存到‘c’中。
Sql代码
create or replace procedure test01 is
cursor cusor_1 is select ename,deptno from emp ;--定义一个游标
begin
for c in cusor_1 loop
dbms_output.put_line('员工姓名:'||c.ename||' 部门编号:'||c.deptno);
end loop;
end test01;
create or replace procedure test01 is
V_TEST number(10):=1;
begin
if V_TEST = 1 then
dbms_output.put_line('1----');
end if;
if V_TEST = 1 then
dbms_output.put_line('1----');
else if V_TEST = 2 then
dbms_output.put_line('2----');
else if V_TEST = 3 then
dbms_output.put_line('3----');
end if;
end if;
end if;
end test01;
2、for语句使用
Sql代码
create or replace procedure test01 is
begin
For x in 0 .. 10 LOOP
dbms_output.put_line(x||'----');
end LOOP;
end test01;
3、游标使用
游标的使用 Oracle 中Cursor 是非常有用的,用于遍历临时表中的查询结果。
将emp表中"ename"和"deptno"查询出,存放到cusor_01游标中。for循环迭代游标集合。每次迭代的结果存到‘c’中。
Sql代码
create or replace procedure test01 is
cursor cusor_1 is select ename,deptno from emp ;--定义一个游标
begin
for c in cusor_1 loop
dbms_output.put_line('员工姓名:'||c.ename||' 部门编号:'||c.deptno);
end loop;
end test01;
相关文章推荐
- oracle存储过程中使用Ref Cursor强类型游标返回结果集
- oracle 存储过程中使用游标
- oracle中存储 过程嵌套游标的使用
- Oracle 存储过程中使用cursor 游标遍历数据
- oracle开发中的存储过程,游标,if判断经典例子
- Oracle存储过程中如何使用游标
- oracle存储过程中游标的使用
- oracle存储过程:游标使用,多重游标
- oracle使用游标 触发器的存储过程
- ORACLE 存储过程使用技巧&游标技巧
- Oracle 存储过程中使用cursor 游标遍历数据
- oracle开发中的存储过程,游标,if判断经典例子
- sql server 函数,存储过程,游标以及while和if语句的嵌套使用
- oracle中建表、游标、存储过程的使用方法入门
- DB2存储过程与oracle的区别for as loop在db2中的使用
- oracle存储过程中 使用游标做循环封装数据集
- Oracle与MySQL存储过程以及游标使用的区别
- oracle 存储过程(其中使用了游标)例子
- oracle 存储过程之游标(loop)使用
- Oracle存储过程中使用游标来批量解析CLOB字段里面的xml字符串: