且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在存储过程中使用oracle对象类型?

更新时间:2022-12-18 13:13:45

在PL/SQL中声明变量时,请先声明该变量的名称,然后是其数据类型.

When you declare variables in PL/SQL, you state the name of the variable first, followed by its datatype.

在您的示例中,您已将behzadtype变量声明为t1类型,然后尝试在代码体中使用名为t1的变量.看来您想将变量t1声明为behzadtype类型.

In your example, you have declared a variable of behzadtype as being of type t1, and then tried to use a variable called t1 in your code body. It looks like you wanted to declare a variable t1 as being of type behzadtype.

此外,您不能为这样的对象分配值-您必须首先将其初始化为对象.

As well as that, you can't assign a value to the object like that - you have to initialise it as an object first.

我认为您追求的是:

create or replace type behzadtype as object 
(sessionid number);
/

create or replace procedure procedure1 as 
  t1 behzadtype;
begin
  t1 := behzadtype(12);
  dbms_output.put_line('THE VALUES OF P_K ARE' || t1.sessionid);
end procedure1;
/

begin
  procedure1;
end;
/

THE VALUES OF P_K ARE12

drop type behzadtype;

drop procedure procedure1;