Oracle 内存中的对象表

发布于 2024-10-05 07:02:32 字数 1003 浏览 1 评论 0原文

我有以下类型:

 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 个值的对象。

有什么想法可以将对象添加到该表中吗?

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 uninitialized 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人疚 2024-10-12 07:02:32

您需要初始化嵌套表:

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

在线文档

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文