Oracle存储过程返数据集(回多个值)
不多说,直接上货。
CREATE OR REPLACE PROCEDURE UP_GETCOMPANYPREVIOUSYEARMONTH(P_CURSOR OUT SYS_REFCURSOR, --返回游标 YEARMONTH IN NUMBER, COMPANYID IN RAW) AS CURRENTYEARJANUARY INTEGER := FLOOR(YEARMONTH / 100) * 100 + 1; CURRENTYEARLASTYEARMNTH1 INTEGER := 0; LASTYEARLASTYEARMNTH1 INTEGER := 0; BEGIN --获取本年度上期报告期 SELECT MAX(YEARMONTH) INTO CURRENTYEARLASTYEARMNTH1 FROM UT_003 WHERE ID_008 = COMPANYID AND YEARMONTH BETWEEN CURRENTYEARJANUARY AND (YEARMONTH - 1); --获取去年同期报告期 SELECT MAX(YEARMONTH) INTO LASTYEARLASTYEARMNTH1 FROM UT_003 WHERE ID_008 = COMPANYID AND YEARMONTH BETWEEN (CURRENTYEARJANUARY - 100) AND (YEARMONTH - 100); --返回上期与去年报告期 OPEN P_CURSOR FOR SELECT CURRENTYEARLASTYEARMNTH1 AS CURRENTYEARLASTYEARMNTH, LASTYEARLASTYEARMNTH1 AS LASTYEARLASTYEARMNTH FROM DUAL; END;