pl/sql 复合类型,游标
2016-05-21 18:26
337 查看
---pl/sql 复合类型,游标
declare
--定义游标类型,sp_emp_cursor
type sp_emp_cursor is ref cursor;
--定义游标变量
var_test_cursor sp_emp_cursor;
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
--执行部分
--把var_test_cursor和一个select结合
open var_test_cursor for select ename,sal from emp where deptno=&no;
--循环取出
loop
fetch var_test_cursor into v_ename,v_sal;
--判断var_test_cursor是否为空
exit when var_test_cursor%notfound;
if v_sal < 2000 then
begin
--薪资低于2000的员工,薪资加100
update emp set sal = sal + 100 where ename=v_ename;
end;
end if;
dbms_output.put_line('名字:'||v_ename||'薪资:'||v_sal);
end loop;
--关闭游标
close var_test_cursor;
end;
declare
--定义游标类型,sp_emp_cursor
type sp_emp_cursor is ref cursor;
--定义游标变量
var_test_cursor sp_emp_cursor;
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
--执行部分
--把var_test_cursor和一个select结合
open var_test_cursor for select ename,sal from emp where deptno=&no;
--循环取出
loop
fetch var_test_cursor into v_ename,v_sal;
--判断var_test_cursor是否为空
exit when var_test_cursor%notfound;
if v_sal < 2000 then
begin
--薪资低于2000的员工,薪资加100
update emp set sal = sal + 100 where ename=v_ename;
end;
end if;
dbms_output.put_line('名字:'||v_ename||'薪资:'||v_sal);
end loop;
--关闭游标
close var_test_cursor;
end;
相关文章推荐
- redis缓存技术
- zabbix3.0.2 使用percona模版监控mysql从库的漏洞修复
- Code First Migrations更新数据库结构的具体步骤
- Oracle数据库中创建自增主键的实例教程
- MySQL中有关char、varchar、int、tinyint、decimal
- 学习MongoDB 十: MongoDB聚合(Map-Reduce)(二)
- linux redis日志文件路径的设置
- redis ,hash
- Oracle数据库中的级联查询、级联删除、级联更新操作教程
- 乐学成语——数据库操作
- Linux下redis安装
- SQL Server使用一个语句块批量插入多条记录的三种方法
- SQL 语句详解
- Redis应用场景
- SQL Server视频总结
- Apache + PHP + MariaDB环境搭建
- nosql基本了解
- Hive连接MongoDB
- MySQL 相关
- SQL Server 使用 SET FMTONLY ON 获得表的元数据