我有以下类型:
create or replace type autocontrole2.DifferentStatesSAC as object (
AUTOCONTROLE_STATUS_CODE_ID NUMBER(2),
DATUM_BEGIN DATE,
DATUM_EIND DATE)
使用以下SQL,错误为“ORA 06531 - 对未初始化集合的引用”
declare
type TableDifferentStatesSAC is table of autocontrole2.DifferentStatesSAC;
StatutenSAC TableDifferentStatesSAC;
begin
StatutenSAC(1).AUTOCONTROLE_STATUS_CODE_ID := 6;
StatutenSAC(1).DATUM_BEGIN := sysdate;
StatutenSAC(1).DATUM_EIND := sysdate;
end;
使用以下SQL,错误是“调用DifferentStatesSAC()时错误的类型或参数数量”:
declare
type TableDifferentStatesSAC is table of autocontrole2.DifferentStatesSAC;
StatutenSAC TableDifferentStatesSAC := autocontrole2.DifferentStatesSAC;
begin
StatutenSAC(1).AUTOCONTROLE_STATUS_CODE_ID := 6;
StatutenSAC(1).DATUM_BEGIN := sysdate;
StatutenSAC(1).DATUM_EIND := sysdate;
end;
我想在内存中创建一个包含3个值的对象的“表”。
如何将对象添加到此表中的任何想法?
答案 0 :(得分:1)
您需要初始化嵌套表:
SQL> DECLARE
2 TYPE TableDifferentStatesSAC IS TABLE OF DifferentStatesSAC;
3 StatutenSAC TableDifferentStatesSAC;
4 BEGIN
5 /* calling the constructor */
6 StatutenSAC := TableDifferentStatesSAC();
7 /* adding room for elements */
8 StatutenSAC.extend();
9 /* filling first element */
10 StatutenSAC(1) := DifferentStatesSAC(6, SYSDATE, SYSDATE);
11 END;
12 /
PL/SQL procedure successfully completed
您也可以使用一个命令填充表格:
SQL> DECLARE
2 TYPE TableDifferentStatesSAC IS TABLE OF DifferentStatesSAC;
3 StatutenSAC TableDifferentStatesSAC;
4 BEGIN
5 /* calling the constructor */
6 StatutenSAC := TableDifferentStatesSAC(
7 DifferentStatesSAC(6, SYSDATE, SYSDATE)
8 );
9 END;
10 /
PL/SQL procedure successfully completed
在online documentation中了解更多信息。