这是我在临时表中使用语句的过程:
CREATE OR REPLACE PROCEDURE dept_query (
p_table CHAR(10),
p_date CHAR(10),
p_start CHAR(6)
)
LANGUAGE SQL
BEGIN
DECLARE v_table VARCHAR(128);
DECLARE v_colname VARCHAR(128);
DECLARE v_month CHAR(6);
DECLARE v_int integer default 0;
DECLARE stat VARCHAR(1000);
DECLARE stmt STATEMENT;
.......
set stat = 'insert into cte1 select colname, row_number() over() as row_nbr from syscat.columns where tabname = ?';
PREPARE stmt FROM stat;
execute stmt using p_table;
set stat = "insert into OH09ZC1.cte3 -- cte, cte1 & cte3 are ordinary tables
with cte2 (list, cnt, cnt_max) AS
(SELECT VARCHAR('', 32000), 0, count(colname) FROM OH09ZC1.cte1
UNION ALL
SELECT
case when cte2.list = '' THEN RTRIM(CHAR(cte1.colname))
else cte2.list || ', ' || RTRIM(CHAR(cte1.colname)) end,
cte2.cnt + 1,
cte2.cnt_max
FROM OH09ZC1.cte1, cte2
WHERE cte1.row_nbr = cte2.cnt + 1 AND cte2.cnt < cte2.cnt_max )
select list FROM cte2 where cte2.cnt = cte2.cnt_max fetch first 1 rows only";
PREPARE stmt FROM stat;
execute stmt;
......
END;
这让我得到了表中列的列表。问题是 'insert into OH09ZC1.cte3 with cte2 (list, cnt, cnt_max) AS' 不包含任何长名称,所以为什么会出现此错误: SQL0107N The name "insert into OH09ZC1.cte3 with cte2 (list , cnt, cnt_max) AS (SELEC" 太长。最大长度为 "128"。当没有“插入 OH09ZC1.cte3”时,我也遇到了同样的错误。