我有一个存储过程,它接受2个输入参数和6个输出参数。其中一个out参数返回多个记录。有没有办法将它声明为数组,因此我不必声明游标。这是代码,
CREATE OR REPLACE PROCEDURE SP_GET_USER_DETAILS
(
P_ID IN OUT VARCHAR2
, P_USER_NAME IN OUT VARCHAR2
, P_USER_TYPE OUT VARCHAR2
, P_EMPLOYEE_ID OUT VARCHAR2
, P_LICENSE_NO OUT VARCHAR2
, P_PHONE_NO OUT VARCHAR2
) IS
BEGIN
SELECT ACCT.ID, ACCT.USERNAME, ACCT.EMPLOYEE_ID, ACCT.LICENSE_NO,
ADDRESS.PHONE_NO INTO P_ID, P_USER_NAME, P_EMPLOYEE_ID, P_LICENSE_NO, P_PHONE_NO
FROM PROVIDER_ACCT ACCT
LEFT OUTER JOIN EMP_ADDRESS ADDRESS ON ACCT.ID=ACCT.ID
END SP_GET_PRISON_USER_DETAILS;
问题是ADDRESS.PHONE_NO单独返回多行。有没有办法将它声明为数组并使其工作?提前谢谢。
如果不可能,请您解释如何使用引用光标进行操作?
答案 0 :(得分:3)
使用集合:
CREATE OR REPLACE PROCEDURE SP_GET_USER_DETAILS
(
P_ID IN OUT VARCHAR2
, P_USER_NAME IN OUT VARCHAR2
, P_USER_TYPE OUT VARCHAR2
, P_EMPLOYEE_ID OUT VARCHAR2
, P_LICENSE_NO OUT VARCHAR2
, P_PHONE_NO OUT SYS.ODCIVARCHAR2LIST
)
IS
BEGIN
SELECT ID,
USERNAME,
EMPLOYEE_ID,
LICENSE_NO
INTO P_ID,
P_USER_NAME,
P_EMPLOYEE_ID,
P_LICENSE_NO
FROM PROVIDER_ACCT;
SELECT ADDRESS.PHONE_NO
BULK COLLECT INTO P_PHONE_NO
FROM PROVIDER_ACCT ACCT
LEFT OUTER JOIN EMP_ADDRESS ADDRESS
ON ACCT.ID = ADDRESS.ID;
END SP_GET_PRISON_USER_DETAILS;
/
注意:您没有在问题中指定where子句 - 您可能想要添加一个。