使用WITH子句(CTE)插入会导致ORA-00928

m.e*_*son 3 sql oracle toad oracle10g sql-insert

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

ORA-00928:缺少SELECT关键字

我要做的就是将结果持久化periods到table中globalTable。选择工作正常(我返回了行),但是一旦将其替换为“插入”,就会出现上述错误。

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;
Run Code Online (Sandbox Code Playgroud)

非常感谢任何指针。

zar*_*tra 5

尝试这个:

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;
Run Code Online (Sandbox Code Playgroud)

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

  • @ m.edmondson:该“文档”被称为“手册”:http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9014.htm#SQLRF55051清楚地表明,“ insert”关键字是后跟一个“值”子句或一个子查询。如果单击“子查询”链接,则会转到“选择”语句的文档,该语句又包含“ with”部分。您应该真正尝试理解那些语法图,这并不是那么令人困惑。 (2认同)