Error: PLS-00642: 在 SQL 语句中不允许使用本地收集类型
TYPE typ_record IS RECORD
(gid NUMBER(10), gno NUMBER(5), co NUMBER(5));
TYPE typ_table IS TABLE OF typ_record;
CREATE OR REPLACE TYPE typ_object AS object
(gid NUMBER(10), gno NUMBER(5), co NUMBER(5));
CREATE OR REPLACE TYPE typ_table AS TABLE OF typ_object;
PLSQL变量可以直接接收BULK COLLECT,但是对象表变量必须先转换
例子:
CREATE OR REPLACE PROCEDURE P_SAMPLE_1 IS
t_sample_1 typ_table;
BEGIN
SELECT t_test.gid, t_test.gno, t_test.co BULK COLLECT
INTO t_sample_1
FROM t_test;
END P_SAMPLE_1;
ORA-00947: 没有足够的值.
如果定义的object变量是单个字段的话,则编译时是提示:
ORA-00932: 数据类型不一致
解决:
CREATE OR REPLACE PROCEDURE P_SAMPLE_1 IS
t_sample_1 typ_table;
BEGIN
SELECT typ_object(t_test.gid, t_test.gno, t_test.co) BULK COLLECT
INTO t_sample_1
FROM t_test;
END P_SAMPLE_1;
整理自:http://www.cnblogs.com/lanzi/archive/2012/01/04/2311431.html