下面显示的PL / SQL脚本无法在第20行执行:
declare
type string_table is table of varchar(100);
v_names string_table := string_table();
begin
v_names.EXTEND(3);
v_names(1) := 'name1';
v_names(2) := 'name2';
v_names(3) := 'name3';
dbms_output.put_line(v_names(1));
dbms_output.put_line(v_names(2));
dbms_output.put_line(v_names(3));
dbms_output.put_line(v_names.COUNT());
20 select * from table(v_names);
end;
以下是报告的错误消息:
ORA-06550: line 20, column 23: PLS-00642: local collection types are not allowed in SQL statements ORA-06550: line 20, column 17: PL/SQL: ORA-22905: cannot access rows from a non-nested table item ORA-06550: line 20, column 3: PL/SQL: SQL Statement ignored.
如何解决此问题的任何想法。
请注意我编写此代码只是为了将此问题发布到SO。类似的代码是更大的包的一部分...
提前致谢!
禅
答案 0 :(得分:3)
您只能对数据库中定义的类型使用SQL(如SELECT),使用CREATE TYPE:
create type string_table is table of varchar(100);
/
然后:
declare
v_names string_table := string_table();
begin
v_names.EXTEND(3);
v_names(1) := 'name1';
v_names(2) := 'name2';
v_names(3) := 'name3';
dbms_output.put_line(v_names(1));
dbms_output.put_line(v_names(2));
dbms_output.put_line(v_names(3));
dbms_output.put_line(v_names.COUNT());
select * from table(v_names);
end;