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

时间:2014-08-15 09:02:52

标签: sql oracle oracle10g sql-insert toad

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

  

ORA-00928:缺少SELECT关键字

我尝试做的只是将periods的结果保留在表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;

非常感谢任何指针。

1 个答案:

答案 0 :(得分:4)

试试这个:

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语句