gpt4 book ai didi

oracle - pl/sql 对象类型 "ORA-06530: Reference to uninitialized composite"错误

转载 作者:行者123 更新时间:2023-12-03 23:48:34 25 4
gpt4 key购买 nike

我有一个类型如下:

CREATE OR REPLACE TYPE tbusiness_inter_item_bag AS OBJECT (
item_id NUMBER,
system_event_cd VARCHAR2 (20),
CONSTRUCTOR FUNCTION tbusiness_inter_item_bag RETURN SELF AS RESULT
);
CREATE OR REPLACE TYPE BODY tbusiness_inter_item_bag
AS
CONSTRUCTOR FUNCTION tbusiness_inter_item_bag RETURN SELF AS RESULT
AS
BEGIN
RETURN;
END;
END;

当我执行以下脚本时,出现“引用未初始化的复合”错误,恕我直言非常合适。
DECLARE
item tbusiness_inter_item_bag;
BEGIN
item.system_event_cd := 'ABC';
END;

这也引发了同样的错误:
item.item_id := 3;

但是,如果我将对象类型更改为:
CREATE OR REPLACE TYPE tbusiness_inter_item_bag AS OBJECT (
item_id NUMBER(1),
system_event_cd VARCHAR2 (20),
CONSTRUCTOR FUNCTION tbusiness_inter_item_bag RETURN SELF AS RESULT
);

然后最后一条语句不再引发错误(我的“项目”仍未初始化):
item.item_id := 3;

我不应该得到相同的 ORA-06530 错误吗?

ps:Oracle 数据库 10g 企业版 10.2.0.4.0 版 - 64bi

最佳答案

我在 Oracle 11gR1 中重现了相同的行为。我同意你的看法,这对我来说也是一个错误,尽管是一个微不足道的错误。

SQL> CREATE OR REPLACE TYPE tbusiness_inter_item_bag AS OBJECT (
2 item_id NUMBER(1),
3 system_event_cd VARCHAR2 (20),
4 CONSTRUCTOR FUNCTION tbusiness_inter_item_bag RETURN SELF AS RESULT
5 );
6 /

Type created.

SQL> DECLARE
2 item tbusiness_inter_item_bag;
3 BEGIN
4 item.item_id := 1;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL>

请注意,这仍然失败:
SQL> DECLARE
2 item tbusiness_inter_item_bag;
3 BEGIN
4 item.item_id := 1;
5 item.system_event_cd := 'ABC';
6 END;
7 /
DECLARE
*
ERROR at line 1:
ORA-06530: Reference to uninitialized composite
ORA-06512: at line 5

SQL>

显然,正确的做法是在引用对象之前初始化对象。
SQL> DECLARE
2 item tbusiness_inter_item_bag := tbusiness_inter_item_bag();
3 BEGIN
4 item.system_event_cd := 'ABC';
5 END;
6 /

PL/SQL procedure successfully completed.

SQL>

关于oracle - pl/sql 对象类型 "ORA-06530: Reference to uninitialized composite"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3021696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com