在PL / SQL过程中引用未初始化的复合错误

时间:2015-07-03 15:05:41

标签: oracle stored-procedures plsql

我是Oracle DB的初学者。我创建了这个对象类型:

create or replace 
TYPE behzadtype AS OBJECT 
( /* TODO enter attribute and method declarations here */ 
  SESSIONID Number,
  myID Number
)

这个存储过程:

create or replace 
PROCEDURE PROCEDURE2(temp in behzadtype) AS 
BEGIN
  insert into beh values(temp.myID,'behiheib');
END PROCEDURE2;

我在运行PL / SQL窗口中执行此存储过程:

DECLARE
  TEMP SYSTEM.BEHZADTYPE;
BEGIN
  -- Modify the code to initialize the variable
  TEMP.myID := 9;

  PROCEDURE2(
    TEMP => TEMP
  );
END;

但是我收到以下错误消息:

Connecting to the database behi.
ORA-06530: Reference to uninitialized composite
ORA-06512: at line 5
Process exited.
Disconnecting from the database behi.

发生什么事了?为什么我会收到这个错误?

1 个答案:

答案 0 :(得分:2)

你必须instantiate它...现在你得到的例外与NullPointerException中的Java相似。

所以在DECLARE

中这样做
DECLARE
    TEMP BEHZADTYPE := BEHZADTYPE(null,null) ;

或者

DECLARE
  TEMP BEHZADTYPE ;
BEGIN
  -- Modify the code to initialize the variable
TEMP := BEHZADTYPE(null,null) ;
  PROCEDURE2(
    TEMP => TEMP
  );
END;