Oracle table of Objects in memory
I've got the following type:
create or replace type autocontrole2.DifferentStatesSAC as object (
AUTOCONTROLE_STATUS_CODE_ID NUMBER(2),
DATUM_BEGIN DATE,
DATUM_EIND DATE)
With the following SQL, the error is "ORA 06531 - reference to uninitiali开发者_Python百科zed collection"
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;
With the following SQL, the error is "wrong number of types or arguments in call to 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;
I want to create a 'table' in memory that contains an object with 3 values.
any ideas how I can add objects to this table?
You need to initialize the nested table:
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
You can also fill the table with a single command:
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
Find out more in the online documentation.
精彩评论