使用 WITH 插入
INSERT INTO by using WITH
我在 dB2 中创建了一个名为 infotext 的 table 用于输出调试某些工件时生成的值。
在 table 信息文本中,我有 2 列称为时间戳类型的数据戳和 varchar(250) 类型的信息。
我遇到的问题与错误有关:
An unexpected token ")" was found following "rom SYSIBM.SYSDUMMY1". Expected tokens may include: ")".. SQLCODE=-104, SQLSTATE=42601
当运行一个陈述如下:
INSERT INTO INFOTEXT (DATESTAMP, INFO)
with datas as (select current timestamp from SYSIBM.SYSDUMMY1),
other AS (
select current timestamp from SYSIBM.SYSDUMMY1);
是什么导致了我的错误?
在查询的最后,您需要在 with 语句之后放置一个 select 子句,您需要一个 select 引用该 CTE。
INSERT INTO INFOTEXT (DATESTAMP, INFO)
with datas as (select current timestamp from SYSIBM.SYSDUMMY1),
other AS (select current timestamp from SYSIBM.SYSDUMMY1)
--just a guess
select * from datas
union all
select * from other;
我在 dB2 中创建了一个名为 infotext 的 table 用于输出调试某些工件时生成的值。
在 table 信息文本中,我有 2 列称为时间戳类型的数据戳和 varchar(250) 类型的信息。
我遇到的问题与错误有关:
An unexpected token ")" was found following "rom SYSIBM.SYSDUMMY1". Expected tokens may include: ")".. SQLCODE=-104, SQLSTATE=42601
当运行一个陈述如下:
INSERT INTO INFOTEXT (DATESTAMP, INFO)
with datas as (select current timestamp from SYSIBM.SYSDUMMY1),
other AS (
select current timestamp from SYSIBM.SYSDUMMY1);
是什么导致了我的错误?
在查询的最后,您需要在 with 语句之后放置一个 select 子句,您需要一个 select 引用该 CTE。
INSERT INTO INFOTEXT (DATESTAMP, INFO)
with datas as (select current timestamp from SYSIBM.SYSDUMMY1),
other AS (select current timestamp from SYSIBM.SYSDUMMY1)
--just a guess
select * from datas
union all
select * from other;