PL/SQL中不通过游标把值添加到集合中
2012-04-13 11:33
162 查看
1.把多行单列的值添加到索引表中(通过RowNum):例如 declare type dname_table_type is table of scott.dept.dname%type index by binary_integer; dname_table dname_table_type; dcount number(2); begin select count(*) into dcount from scott.dept; for i in 1..dcount loop select t1.dname into dname_table(i) from (select rownum rn,t.* from (select * from scott.dept)t)t1 where t1.rn=i; end loop; for i in 1..dname_table.count loop dbms_output.put_line(dname_table(i)); end loop; end; 2.PL/SQL记录表把多行多列的值添加到集合中(RowType):例如: declare type dname_table_type is table of scott.dept%rowtype index by binary_integer; dname_table dname_table_type; dcount number(2); begin select count(*) into dcount from scott.dept; for i in 1..dcount loop select t1.deptno,t1.dname,t1.loc into dname_table(i) from (select rownum rn,t.* from scott.dept t)t1 where t1.rn=i; end loop; for i in 1..dname_table.count loop dbms_output.put_line(dname_table(i).dname||' '||dname_table(i).deptno); end loop; end; 3.PL/SQL记录表把多行多列的值添加到集合表中(ReCord),自定义二维表:例如: declare type dept_record_type is record( deptno scott.dept.deptno%type, dname scott.dept.dname%type, dloc scott.dept.loc%type ); type dname_table_type is table of dept_record_type(数据类型) index by binary_integer; dname_table dname_table_type; dcount number(2); begin select count(*) into dcount from scott.dept; for i in 1..dcount loop select t1.deptno,t1.dname,t1.loc into dname_table(i) from (select rownum rn,t.* from scott.dept t)t1 where t1.rn=i; end loop; for i in 1..dname_table.count loop dbms_output.put_line(dname_table(i).dname||' '||dname_table(i).deptno); end loop; end;
相关文章推荐
- oracle pl_sql 通过游标循环取数字的方法
- PL/SQL 游标FOR循环
- PL/SQL 游标变量
- 黑马程序员 :(反射应用 )通过反射讲<Integer>类型的集合中添加一个<String>类型的数据
- 通过PL/SQL导入excel文件
- ORACLE PL/SQL 集合学习笔记(一)
- ORACLE PL/SQL编程之四:把游标说透
- PL/SQL 游标
- PL/SQL语法 - 游标
- PL/SQL之显示游标使用
- PL/SQL cursor 游标 where条件接收形参为VARCHAR 不能正常执行的问题 SELECT ContactNameC FROM MTContact WHERE objectno
- 通过pl_sql 把 oracle导出用户空间下的表的建表语句
- MySQL通过视图(或临时表)实现动态SQL(游标)
- 再次提供一个纯粹通过pl/sql解析json的方法。
- PL/SQL --> 游标
- PL/SQL语句块基本语法(ORACLE存储过程,函数,包,游标) (转)
- PL/SQL developer基础语法学习(三)之游标
- oracle pl sql 游标
- PL/SQL中的集合类型
- PL/SQL&nbsp;集合的方法