从 PL/SQL 调用此查询时出现 ORA-06502 错误。但是,如果我从 SQL 提示符尝试它正在工作。
在 SQL 提示符下,这给出了预期的输出:
SELECT *
FROM
(
SELECT
COL.BAN,
MAX (COL.COL_ACTV_CODE) AS COL_ACTV_CODE,
MAX (TO_CHAR(COL.COL_ACTV_DATE,'MM')) AS COL_ACTV_DATE
FROM
COLLECTION COL,
COLLECTION_ACTIVITIES CAC
WHERE (CAC.SEVERITY_LEVEL , TO_CHAR(COL.COL_ACTV_DATE,'YYYYMM')) IN
(SELECT
MAX(CAC.SEVERITY_LEVEL),
MAX(TO_CHAR(COL.COL_ACTV_DATE, 'YYYYMM'))
FROM
COLLECTION COL,
COLLECTION_ACTIVITIES CAC
WHERE
COL.COL_ACTV_CODE = CAC.COL_ACTIVITY_CODE
GROUP BY TO_CHAR (COL.COL_ACTV_DATE , 'YYYYMM')
)
GROUP BY COL.BAN
ORDER BY TO_CHAR (COL.COL_ACTV_DATE , 'YYYYMM') DESC
)
PIVOT
(
MAX( COL_ACTV_CODE)
FOR COL_ACTV_DATE in ('01' as "JAN", '02' as "FEB", '03' as "MAR"));
BAN J F M A M J J A S O N D
---------- - - - - - - - - - - - -
90314228 W
90314009 K
90314748 E
90314568 E
90314328 W
但是从 PL/SQL:
BEGIN
STMT_STR := 'CREATE TABLE ACD_COL_ST
PCTUSED 90
NOLOGGING
AS
SELECT *
FROM
(
SELECT
COL.BAN,
MAX (COL.COL_ACTV_CODE) AS COL_ACTV_CODE,
MAX (TO_CHAR(COL.COL_ACTV_DATE,'MM')) AS COL_ACTV_DATE
FROM
COLLECTION COL,
COLLECTION_ACTIVITIES CAC
WHERE (CAC.SEVERITY_LEVEL , TO_CHAR(COL.COL_ACTV_DATE,'YYYYMM')) IN
(SELECT
MAX(CAC.SEVERITY_LEVEL),
MAX(TO_CHAR(COL.COL_ACTV_DATE, 'YYYYMM'))
FROM
COLLECTION COL,
COLLECTION_ACTIVITIES CAC
WHERE
COL.COL_ACTV_CODE = CAC.COL_ACTIVITY_CODE
GROUP BY TO_CHAR (COL.COL_ACTV_DATE , 'YYYYMM')
)
GROUP BY COL.BAN
ORDER BY TO_CHAR (COL.COL_ACTV_DATE , 'YYYYMM') DESC
)
PIVOT
(
MAX( COL_ACTV_CODE)
FOR COL_ACTV_DATE in ('01' as "JAN", '02' as "FEB", '03' as "MAR"))';
EXECUTE IMMEDIATE STMT_STR;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error was encountered creating table ACD_COL_ST'||SQLCODE||' - ERROR - '||SQLERRM);
END;
COMMIT;
我收到一个错误:
ORA-06502: PL/SQL: 数字或值错误: 字符串缓冲区太小