我有一些旧的SP,它们的输出参数类型为'table of',就像这样......
TYPE tblSAM_DD_TEXT IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
TYPE tblSAM_TYPE IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
TYPE tbl_CONSOLIDATED_ID IS TABLE OF VARCHAR2(32) INDEX BY BINARY_INTEGER;
PROCEDURE Get_Associated_Unicorns(
UNIID_IN IN ABC_UNICORNS.UNI_AUTOID%TYPE,
ID_OUT OUT tbl_CONSOLIDATED_ID,
SAMDDTEXT_OUT OUT tblSAM_DD_TEXT,
SAMTYPE_OUT OUT tblSAM_TYPE
);
...我想调整现有的处理方式,以便sp的原型看起来像这样......
TYPE t_cursor IS REF CURSOR ;
PROCEDURE Get_Associated_Unicorns(
UNIID_IN IN ABC_UNICORNS.UNI_AUTOID%TYPE,
v_cursor OUT t_cursor
);
...所以有人打电话给 Get_Associated_Unicorns 会有一个参考光标而不是三个''对象'。
使用Oracle 10g PL / SQL如何调整现有的SP,以便迭代'table of'对象来填充引用游标,这是唯一的输出参数?
(三个''参数表总是具有相同的长度)。
答案 0 :(得分:1)
如果您首先在数据库中创建3种类型
CREATE TYPE tblSAM_DD_TEXT IS TABLE OF VARCHAR2(50);
CREATE TYPE tblSAM_TYPE IS TABLE OF NUMBER;
CREATE TYPE tbl_CONSOLIDATED_ID IS TABLE OF VARCHAR2(32);
然后您可以在程序中引用它们
CREATE or REPLACE PROCEDURE Get_Associated_Unicorns
( p_tblSAM_DD_TEXT IN tblSAM_DD_TEXT
,p_tblSAM_TYPE IN tblSAM_TYPE
,p_tbl_CONSOLIDATED_ID IN tbl_CONSOLIDATED_ID
,pc_refcursor OUT sys_refcursor)
BEGIN
OPEN pc_refcursor FOR
SELECT tblSAM_DD_TEXT SAM_DD_TEXT
,tblSAM_TYPE SAM_TYPE
,tbl_CONSOLIDATED_ID CONSOLIDATED_ID
FROM (SELECT column_value tblSAM_DD_TEXT
,rownum r1
FROM TABLE(p_tblSAM_DD_TEXT))
,(SELECT column_value tblSAM_TYPE
,rownum r2
FROM TABLE(p_tblSAM_TYPE))
,(SELECT column_value tbl_CONSOLIDATED_ID
,rownum r3
FROM TABLE(p_tbl_CONSOLIDATED_ID))
WHERE r1 = r2
AND r2 = r3;
END;