【问题标题】:Insert Into using a WITH clause (CTE) causes a ORA-00928使用 WITH 子句 (CTE) 插入会导致 ORA-00928
【发布时间】:2014-08-15 09:02:51
【问题描述】:

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

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;

任何指针都非常感谢。

【问题讨论】:

    标签: sql oracle oracle10g sql-insert toad


    【解决方案1】:

    试试这个:

    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 子句)是SELECT 语句的一部分,根据INSERT 语法,您可以指定值或SELECT 语句

    【讨论】:

    • 有没有围绕这个顺序的语法的文档? Oracle 有时确实让我感到困惑。
    • @m.edmondson: that "document" is called "the manual": docs.oracle.com/cd/E11882_01/server.112/e26088/… 清楚地表明insert 关键字后跟values 子句或子查询。如果您单击subquery 链接,您将转到select 语句的文档,该语句又包含with 部分。你真的应该试着理解那些语法图,它不会那么混乱。
    • @m.edmondson CTE 是SELECT 语句的一部分,根据INSERT syntax 您可以指定values 语句或select 语句
    猜你喜欢
    • 2022-07-17
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2021-10-16
    • 1970-01-01
    • 2019-03-03
    相关资源
    最近更新 更多