oracle过程返回自定义数据类型记录的表
我创建了“object”类型的自定义数据类型 我创建了一个记录类型的表oracle过程返回自定义数据类型记录的表,oracle,stored-procedures,plsql,record,custom-data-type,Oracle,Stored Procedures,Plsql,Record,Custom Data Type,我创建了“object”类型的自定义数据类型 我创建了一个记录类型的表 create type mytableobject is table of myrecord; 现在,我已经使用 "execute immediate" (select * from table1) bulk collect into mytableobject. 我想在存储过程中返回这个mytableobject 我如何做到这一点? 如何调用该过程?您可以使用自己的类型作为存储过程的OUT参数。您显示的表人口没有多大意
create type mytableobject is table of myrecord;
现在,我已经使用
"execute immediate" (select * from table1) bulk collect into mytableobject.
我想在存储过程中返回这个mytableobject
我如何做到这一点?
如何调用该过程?您可以使用自己的类型作为存储过程的
OUT
参数。您显示的表人口没有多大意义,因此我认为这是您必须真正做的:
create or replace procedure myproc(mytable out mytableobject) is
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
end myproc;
/
然后,您可以通过声明该类型的局部变量并将其传入,从另一个过程或匿名块调用它:
declare
tab mytableobject;
begin
myproc(tab);
end;
/
您更可能需要一个函数,尤其是在您提到返回它之后。这几乎是一样的:
create or replace function myfunc
return mytableobject is
mytable mytableobject;
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
return mytable;
end myfunc;
/
declare
tab mytableobject;
begin
tab := myfunc;
end;
/
但更有用的是,您可以从SQL调用函数:
select * from table(myfunc);
.您可以使用自己的类型作为存储过程的
OUT
参数。您显示的表人口没有多大意义,因此我认为这是您必须真正做的:
create or replace procedure myproc(mytable out mytableobject) is
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
end myproc;
/
然后,您可以通过声明该类型的局部变量并将其传入,从另一个过程或匿名块调用它:
declare
tab mytableobject;
begin
myproc(tab);
end;
/
您更可能需要一个函数,尤其是在您提到返回它之后。这几乎是一样的:
create or replace function myfunc
return mytableobject is
mytable mytableobject;
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
return mytable;
end myfunc;
/
declare
tab mytableobject;
begin
tab := myfunc;
end;
/
但更有用的是,您可以从SQL调用函数:
select * from table(myfunc);
.您可以使用自己的类型作为存储过程的
OUT
参数。您显示的表人口没有多大意义,因此我认为这是您必须真正做的:
create or replace procedure myproc(mytable out mytableobject) is
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
end myproc;
/
然后,您可以通过声明该类型的局部变量并将其传入,从另一个过程或匿名块调用它:
declare
tab mytableobject;
begin
myproc(tab);
end;
/
您更可能需要一个函数,尤其是在您提到返回它之后。这几乎是一样的:
create or replace function myfunc
return mytableobject is
mytable mytableobject;
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
return mytable;
end myfunc;
/
declare
tab mytableobject;
begin
tab := myfunc;
end;
/
但更有用的是,您可以从SQL调用函数:
select * from table(myfunc);
.您可以使用自己的类型作为存储过程的
OUT
参数。您显示的表人口没有多大意义,因此我认为这是您必须真正做的:
create or replace procedure myproc(mytable out mytableobject) is
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
end myproc;
/
然后,您可以通过声明该类型的局部变量并将其传入,从另一个过程或匿名块调用它:
declare
tab mytableobject;
begin
myproc(tab);
end;
/
您更可能需要一个函数,尤其是在您提到返回它之后。这几乎是一样的:
create or replace function myfunc
return mytableobject is
mytable mytableobject;
begin
select myrecord(col1, col2)
bulk collect into mytable
from table1;
return mytable;
end myfunc;
/
declare
tab mytableobject;
begin
tab := myfunc;
end;
/
但更有用的是,您可以从SQL调用函数:
select * from table(myfunc);
.为什么
立即执行
,为什么用双引号?您的过程目前看起来是什么样子,您如何调用它?从何处调用?为什么立即执行,为什么使用双引号?您的过程目前看起来是什么样子,您如何调用它?从何处调用?为什么立即执行,为什么使用双引号?您的过程目前看起来是什么样子,您如何调用它?从何处调用?为什么立即执行,为什么使用双引号?目前您的程序是什么样子的?您如何称呼它?从哪里开始?