我想在DB2版本11.1.0中使用CTAS语句,它创建一个新表并插入它。查询如下:DB2 CTAS令牌错误
CREATE TABLE MY_SCRATCH.LC$U7OB81478732948714_zero_to_3 AS (
WITH two AS (SELECT id AS the_num FROM users WHERE id = 2)
, one_two AS (
SELECT id AS the_num FROM users WHERE id = 1
UNION ALL
SELECT * FROM two tmp
)
, zero_one_two AS (
SELECT id-7 AS the_num FROM users where id = 7
UNION ALL
SELECT * FROM one_two tmp
)
SELECT * FROM zero_one_two tmp
UNION ALL
SELECT id AS the_num FROM users WHERE id = 3
) WITH DATA
不过,我收到以下错误:
"my_error":"SQL Error: derived_table zero_to_3 creation failed: SQL Error in CREATE TABLE as SELECT: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=AS;RO_TO_3\" (\nWITH TWO;JOIN, DRIVER=4.16.53"
据DB2 docs,错误是因为以下几点:
A syntax error was detected where the symbol "token" occurs in the SQL statement. The list of symbols that might be legal shows some alternate symbols that could possibly be correct at that point, if the preceding part of the statement is entirely correct.
所以我在RazorSQL中运行上述查询,并且抛出了相同的错误。不太确定令牌问题的位置是
包括列名称的预期表结构是什么? –