sql - Insert Into 使用 WITH 子句 (CTE) 导致 ORA-00928

标签 sql oracle oracle10g sql-insert toad

我正在尝试做一个本质上非常简单的任务,结果是:

ORA-00928: missing SELECT keyword

我要做的就是将 periods 的结果保存到表 globalTable 中。选择工作正常(我返回行)但是一旦我用 Insert 替换它我就会收到上述错误。

create global temporary table globalTable
(
    ids number(11)
);

with periods as
(
select cl.id uniqueId
from inv_mpan_hh_con_lines cl
left join invoice_vat_lines vl on
                 cl.invoice_id = VL.INVOICE_ID
where rownum < 4
)

--//Issue occurs at insert keyword.  If I comment it and uncomment select it works as expected//--
--select uniqueId
insert into globalTable
from periods;

非常感谢任何指点。

最佳答案

试试这个:

insert into globalTable
with periods as
(
select cl.id uniqueId
from inv_mpan_hh_con_lines cl
left join invoice_vat_lines vl
  on cl.invoice_id = VL.INVOICE_ID
where rownum < 4
)
select uniqueId
  from periods;

CTE (WITH-clause) 是 SELECT 语句的一部分,根据 INSERT 语法,您可以指定值或 SELECT 语句

关于sql - Insert Into 使用 WITH 子句 (CTE) 导致 ORA-00928,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25323833/

相关文章:

java - 无法使用 19.3 JDBC 驱动程序连接到 Oracle 19.3

sql - Oracle将行重复N次,其中N是列

sql - Oracle中如何获取该变量的值?

SQL:将查询输出更改为具有两个单独的列,而不是具有 2 个值的行

sql - 将 SQL 查询限制为每个组的前两个计数

带有 Oracle 数据库的 .NET 应用程序

sql - 如何将多个数据库合并为一个源

php - 使用 PHP 更新 sql 表中的字段

sql - CROSS JOIN 和一表多表 FROM 有什么区别?

sql - 将行/记录中的多个数据合并到带有逗号分隔字段的一行中