У меня есть следующий код:
v_SQL := '
-- ==========================================================
-- Main Unpivot Table - To move years from column headings
-- to rows values
-- ==========================================================
SELECT
CAST(FieldYear AS Number) FieldYear
, FieldType
, CASE FieldValue
WHEN '''' THEN NULL
ELSE CAST (FieldValue AS Number(38,8))
END FieldValue
FROM
(SELECT ' ||
v_InsertType ||' AS FieldType
,Y1 as ' || CAST(v_FY0 - 5 - v_OffSet AS CHAR) || '
,Y2 as ' || CAST(v_FY0 - 4 - v_OffSet AS CHAR) || '
,Y3 as ' || CAST(v_FY0 - 3 - v_OffSet AS CHAR) || '
,Y4 as ' || CAST(v_FY0 - 2 - v_OffSet AS CHAR) || '
,Y5 as ' || CAST(v_FY0 - 1 - v_OffSet AS CHAR) || '
,Y6 as ' || CAST(v_FY0 - v_OffSet AS CHAR) || '
,Y7 as ' || CAST(v_FY0 + 1 - v_OffSet AS CHAR) || '
,Y8 as ' || CAST(v_FY0 + 2 - v_OffSet AS CHAR) || '
,Y9 as ' || CAST(v_FY0 + 3 - v_OffSet AS CHAR) || '
,Y10 as ' || CAST(v_FY0 + 4 - v_OffSet AS CHAR) || '
,Y11 as ' || CAST(v_FY0 + 5 - v_OffSet AS CHAR) || '
,Y12 as ' || CAST(v_FY0 + 6 - v_OffSet AS CHAR) || '
,Y13 as ' || CAST(v_FY0 + 7 - v_OffSet AS CHAR) || '
,Y14 as ' || CAST(v_FY0 + 8 - v_OffSet AS CHAR) || '
,Y15 as ' || CAST(v_FY0 + 9 - v_OffSet AS CHAR) || '
,Y16 as ' || CAST(v_FY0 + 10 - v_OffSet AS CHAR) || '
,Y17 as ' || CAST(v_FY0 + 11 - v_OffSet AS CHAR) || '
,Y18 as ' || CAST(v_FY0 + 12 - v_OffSet AS CHAR) || '
,Y19 as ' || CAST(v_FY0 + 13 - v_OffSet AS CHAR) || '
,Y20 as ' || CAST(v_FY0 + 14 - v_OffSet AS CHAR) || '
,Y21 as ' || CAST(v_FY0 + 15 - v_OffSet AS CHAR) || '
,Y22 as ' || CAST(v_FY0 + 16 - v_OffSet AS CHAR) || '
,Y23 as ' || CAST(v_FY0 + 17 - v_OffSet AS CHAR) || '
,Y24 as ' || CAST(v_FY0 + 18 - v_OffSet AS CHAR) || '
,Y25 as ' || CAST(v_FY0 + 19 - v_OffSet AS CHAR) || '
,Y26 as ' || CAST(v_FY0 + 20 - v_OffSet AS CHAR) || '
,Y27 as ' || CAST(v_FY0 + 21 - v_OffSet AS CHAR) || '
,Y28 as ' || CAST(v_FY0 + 22 - v_OffSet AS CHAR) || '
,Y29 as ' || CAST(v_FY0 + 23 - v_OffSet AS CHAR) || '
,Y30 as ' || CAST(v_FY0 + 24 - v_OffSet AS CHAR) || '
,Y31 as ' || CAST(v_FY0 + 25 - v_OffSet AS CHAR) || '
,Y32 as ' || CAST(v_FY0 + 26 - v_OffSet AS CHAR) || '
,Y33 as ' || CAST(v_FY0 + 27 - v_OffSet AS CHAR) || '
,Y34 as ' || CAST(v_FY0 + 28 - v_OffSet AS CHAR) || '
,Y35 as ' || CAST(v_FY0 + 29 - v_OffSet AS CHAR) || '
FROM ' ||
v_tblInsertType || ') UP
UNPIVOT
(FieldValue FOR FieldYear IN
(' || CAST(v_FY0 - 5 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 - 4 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 - 3 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 - 2 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 - 1 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 1 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 2 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 3 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 4 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 5 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 6 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 7 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 8 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 9 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 10 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 11 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 12 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 13 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 14 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 15 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 16 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 17 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 18 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 19 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 20 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 21 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 22 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 23 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 24 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 25 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 26 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 27 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 28 - v_OffSet AS CHAR) || '
,' || CAST(v_FY0 + 29 - v_OffSet AS CHAR) || '
)
)AS unpvt
Execute immediate v_SQL;
, где v_FY0 - это NUMBER (10); v_SQL NVarchar2 (4000), v_InsertType VARCHAR2 (4000); и номер v_OffSet (10); v_tblInsertType VARCHAR2 (4000);
После выполнения я получаю: v_FY0 = 2018 и v_OffSet = 0;
При выполнении я получаю сообщение об ошибке - ORA-00923: ключевое слово FROM не найдено там, где ожидается.
Как решить эту проблему и как заставить это работать.