17,377
社区成员
发帖
与我相关
我的任务
分享
原表是:mdsys.emp (记录举例)
DEPTID DEPTNAME EMPID EMPNAME SALARY
------ ---------- ------ ---------- -----------
1 销售部 1 陈一 1200
1 销售部 2 陈二 4500
1 销售部 3 陈三 4900
2 市场部 4 陈三 2000
SQL> declare
2 type name_array_type is varray(10) of varchar2(10);
3 name_array name_array_type;
4 cursor emp_cursor is select empname from mdsys.emp;
5
6 begin
7 open emp_cursor;
8 fetch emp_cursor bulk collect into name_array limit 10;
9 for i in 1..10 loop
10 dbms_output.put(name_array(i));
11 end loop;
12 close emp_cursor;
13 end ;
14 /
PL/SQL procedure successfully completed (这里没有记录输出来啊。。。。)
奇怪的事情是我执行了另外一个程序,结果却在那个程序结果里面出来了。。。。
SQL> declare
2 type name_array_type is varray(5) of varchar2(10);
3 name_array name_array_type;
4 cursor emp_cursor is select empname from mdsys.emp;
5 rows int :=5;
6 v_count int :=0;
7 begin
8 open emp_cursor;
9 loop
10 fetch emp_cursor bulk collect into name_array limit rows;
11 dbms_output.put('雇员名:');
12 for i in 1..(emp_cursor%rowcount-v_count) loop
13 dbms_output.put(name_array(i)||' ');
14 end loop;
15 dbms_output.new_line;
16 v_count:=emp_cursor%rowcount;
17 exit when emp_cursor%notfound;
18 end loop;
19 close emp_cursor;
20 end;
21 /
王丽刘娜袁野李欣刘明雇员名:袁野 王丽 刘娜 李欣 刘明
雇员名:张亚东 刘明凯 季岚 梁栋 汤佳
雇员名:田康 陈巍伟 孙鹏 巍伟 陈淑华
雇员名:王朋 单红 王祥
请大侠帮我看看是什么问题。。。先谢过~
DECLARE
TYPE name_array_type IS VARRAY(20) OF VARCHAR2(20);
name_array name_array_type;
CURSOR emp_cursor is select EmpName from T146;
BEGIN
OPEN emp_cursor;
FETCH emp_cursor BULK COLLECT INTO name_array ;
FOR i IN 1..4 LOOP
dbms_output.put(name_array(i));
END LOOP;
dbms_output.put_line(''); --加一行代码
CLOSE emp_cursor;
END;
fetch emp_cursor bulk collect into name_array limit 10;
SQL> declare
2 type name_array_type is varray(10) of varchar2(10);
3 name_array name_array_type;
4 cursor emp_cursor is select empname from mdsys.emp;
5
6 begin
7 open emp_cursor;
8 loop
9 fetch emp_cursor bulk collect into name_array limit 10;
10 exit when name_array.count=0;
11 end loop;
12 for i in 1..10 loop
13 dbms_output.put(name_array(i));
14 end loop;
15 close emp_cursor;
16 end ;