我是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.
发生什么事了?为什么我会收到这个错误?
答案 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;