Database Oracle存储过程-我可以返回一个由多个其他结构组成的复合类型吗?
我想在Oracle(11g)中创建一个存储过程,它将从由FK连接的14-16个表中获取数据。 逻辑如下- 1.从输入参数中提取主表中的键。 2.使用键从所有其他表中提取数据 我还想创建与每个表和复合类型对齐的Oracle类型,这些表和复合类型将包含所有这些类型数组 注意事项:Database Oracle存储过程-我可以返回一个由多个其他结构组成的复合类型吗?,database,algorithm,plsql,oracle11g,Database,Algorithm,Plsql,Oracle11g,我想在Oracle(11g)中创建一个存储过程,它将从由FK连接的14-16个表中获取数据。 逻辑如下- 1.从输入参数中提取主表中的键。 2.使用键从所有其他表中提取数据 我还想创建与每个表和复合类型对齐的Oracle类型,这些表和复合类型将包含所有这些类型数组 注意事项: 很少有表没有该键的数据。如果数据丢失,我会返回该表的空结构 对于给定的键,某些表可能有多行。我们将填充映射到该表的类型数组 我对oracle编程还很陌生。我想了解,是否可以从SP返回复合类型? 如果不可能,我是否可以从SP
如果不可能,我是否可以从SP返回多个类型数组?当然,您可以这样做。假设您的类型是XYZ_类型。您需要创建一个函数(如果您想返回一个类型实例,它必须是一个函数),如下所示
共享和享受。是的,可以在SQL和PL/SQL中构建复合类型。下面是一个使用对象类型的示例:
drop table table2;
create table table1(a number, b number);
create table table2(a number, b number);
create or replace type table1_type is object
(
a number,
b number
);
create or replace type table2_type is object
(
a number,
b number
);
create or replace type table1_nt is table of table1_type;
create or replace type table2_nt is table of table1_type;
create or replace type table_1_2_type is object
(
table1 table1_nt,
table2 table2_nt
);
table_1_2_type
现在可以用作返回类型或输出类型
不幸的是,类型定义非常重复。%TYPE和%ROWTYPE运算符在SQL中不起作用,根据您使用这些对象的方式,它们必须定义为SQL类型。pl/SQL中的结构是什么?您可以构建一个ref游标并返回其中所需的任何内容,或者使用pl/sql集合。去读它的类型-创建或替换类型XYZ作为对象(col1 VARCHAR2(2字节),col2 VARCHAR2(10字节)),然后编辑你的问题并称它为什么。
drop table table2;
create table table1(a number, b number);
create table table2(a number, b number);
create or replace type table1_type is object
(
a number,
b number
);
create or replace type table2_type is object
(
a number,
b number
);
create or replace type table1_nt is table of table1_type;
create or replace type table2_nt is table of table1_type;
create or replace type table_1_2_type is object
(
table1 table1_nt,
table2 table2_nt
);