create or replace PROCEDURE SearchResult
( V_ID IN VARCHAR2
, V_REFCUR OUT SYS_REFCURSOR
)
IS
BEGIN
DECLARE CNT INT;
BEGIN
SELECT COUNT(*) INTO CNT
FROM TABLE1 T1
INNER JOIN TABLE2 T2 ON T1.CODE = T2.CODE
WHERE T1.ID = V_ID;
IF (CNT > 0) THEN
OPEN V_REFCUR FOR
SELECT T1.TYPE
FROM TABLE T1
INNER JOIN TABLE2 T2 ON T1.CODE = T2.CODE
WHERE T1.ID = V_ID AND T1.TYPE IS NOT NULL;
ELSE
OPEN V_REFCUR FOR
SELECT
T3.NAME||T1.TYPE
FROM TABLE3 T3
INNER JOIN TABLE2 T2 ON T2.ID= T3.ID
INNER JOIN TABLE1 T1 ON T1.CODE = T2.CODE
AND TI.TYPE IS NOT NULL AND T1.ID = V_ID;
END IF;
END;
BEGIN
OPEN V_REFCUR FOR
SELECT
T1.NAME
, T1.ADDRESS
FROM TABLE1 T1
WHERE T1.ID = V_ID
END;
END SearchResult
答案 0 :(得分:2)
要将单独查询的结果合并到同一个表格中,您可以使用以下几个选项:
Union all
,使用exclude duplicates或Insert
将两个查询合并为一个。