ORA-06530: 引用未初始化的组合 ;

时间:2023-12-30 22:02:02

select * FROM TABLE(fun_test_1) ;
 
ORA-06530: 引用未初始化的组合
ORA-06512: 在 "PCISS.FUN_TEST_1", line 10
 
SQL>

---抛错代码

 CREATE OR REPLACE  TYPE table_test2 IS OBJECT(
SID INTEGER ,
sname VARCHAR2(50),
age INT ,
sex varchar2(2),
addres Varchar2(100)
);
/
CREATE OR REPLACE TYPE typ_test2_table IS TABLE OF table_test2 ;
/
CREATE OR REPLACE FUNCTION fun_test_1 RETURN typ_test2_table PIPELINED AS
rec_test2 test2%ROWTYPE ;
tab_test2 table_test2 ;
BEGIN
SELECT * INTO rec_test2 FROM test2 t WHERE t.sid=1 ;
tab_test2.sid := rec_test2.sid ;
tab_test2.sname := rec_test2.sname ;
tab_test2.age := rec_test2.age ;
tab_test2.sex := rec_test2.sex ;
tab_test2.addres := rec_test2.addres ;
PIPE ROW(tab_test2);
RETURN ;
end fun_test_1;
/

---抛错原因;

 CREATE OR REPLACE FUNCTION FUN_TEST_1 RETURN TYP_TEST2_TABLE
PIPELINED AS
REC_TEST2 TEST2%ROWTYPE;
TAB_TEST2 TABLE_TEST2 /* := TABLE_TEST2(NULL, NULL, NULL, NULL, NULL)*/
;
CURSOR CUR IS
SELECT E.EMPNO, E.ENAME, E.DEPTNO, 'na', E.JOB FROM EMP E;
BEGIN
SELECT * INTO REC_TEST2 FROM TEST2 T WHERE T.SID = 1;
TAB_TEST2.SID := REC_TEST2.SID;
TAB_TEST2.SNAME := REC_TEST2.SNAME;
TAB_TEST2.AGE := REC_TEST2.AGE;
TAB_TEST2.SEX := REC_TEST2.SEX;
TAB_TEST2.ADDRES := REC_TEST2.ADDRES;
PIPE ROW(TAB_TEST2); TAB_TEST2.SID := 7788;
TAB_TEST2.SNAME := 'admin';
TAB_TEST2.AGE := 21;
TAB_TEST2.SEX := '男';
TAB_TEST2.ADDRES := '上海';
PIPE ROW(TAB_TEST2); OPEN CUR;
LOOP
FETCH CUR
INTO TAB_TEST2.SID,
TAB_TEST2.SNAME,
TAB_TEST2.AGE,
TAB_TEST2.SEX,
TAB_TEST2.ADDRES; EXIT WHEN CUR%NOTFOUND;
PIPE ROW(TAB_TEST2);
END LOOP;
  close cur ;
RETURN;
END FUN_TEST_1;