集合在 PLSQL 中不起作用
Collections not working in PLSQL
以下代码不适用于 PLSQL 上的游标。
我收到一条错误消息。
declare
type abc is varray(10) of number;
cursor x is select Empno from emp where rownum <10;
a abc;
counter number :=1;
begin
a:=abc();
for i in x
loop
a.extend();
a(i):=counter.Empno;
DBMS_output.put_line(a(i));
counter:= end loop;
end;
您使用了 counter
而不是 for loop iterator
i
:
尝试;
declare
type abc is varray(10) of number;
cursor x is select Empno from emp where rownum <10;
a abc;
counter number := 1;
begin
a:=abc();
for i in x loop
a.extend();
a(counter) := i.Empno;
DBMS_output.put_line(a(counter));
counter := counter + 1;
end loop;
end;
或者您可以使用 Bulk collect
将数据插入 varray
declare
type abc is varray(10) of number;
a abc := abc();
begin
select Empno BULK COLLECT INTO a from emp where rownum <10;
for i in 1 .. a.count loop
DBMS_output.put_line(a(i));
end loop;
end;
以下代码不适用于 PLSQL 上的游标。 我收到一条错误消息。
declare
type abc is varray(10) of number;
cursor x is select Empno from emp where rownum <10;
a abc;
counter number :=1;
begin
a:=abc();
for i in x
loop
a.extend();
a(i):=counter.Empno;
DBMS_output.put_line(a(i));
counter:= end loop;
end;
您使用了 counter
而不是 for loop iterator
i
:
尝试;
declare
type abc is varray(10) of number;
cursor x is select Empno from emp where rownum <10;
a abc;
counter number := 1;
begin
a:=abc();
for i in x loop
a.extend();
a(counter) := i.Empno;
DBMS_output.put_line(a(counter));
counter := counter + 1;
end loop;
end;
或者您可以使用 Bulk collect
将数据插入 varray
declare
type abc is varray(10) of number;
a abc := abc();
begin
select Empno BULK COLLECT INTO a from emp where rownum <10;
for i in 1 .. a.count loop
DBMS_output.put_line(a(i));
end loop;
end;