【问题标题】:Insert multiple rows with multiple values nextval Oracle SQL插入具有多个值的多行 nextval Oracle SQL
【发布时间】:2017-04-27 16:13:38
【问题描述】:

我正在尝试将具有多个值和 test_id.nextval 的 2 行插入现有数据框中,而不在代码中包含列标题:

insert into x
    select * from
        (select 12345, 'text', test_id_seq.nextval from dual
    union all
        select 23589, 'other text', test_id_seq.nextval from dual);

我收到错误消息:sequence number not allowed here。所以我删除了序列号。然后出现错误not enough values。 如何将多行插入到具有 nextval id 的现有表中?

【问题讨论】:

    标签: sql oracle insert nextval


    【解决方案1】:

    试试这个:

        insert into x
        select tt.* , test_id_seq.nextval from
        (select 12345, 'text' from dual
        union all
        select 23589, 'other text' from dual) tt;
    

    【讨论】:

    • 一开始你的代码可以工作,但之后我添加了不同的值,它就不再工作了。 insert into a_glw select tt.*, work_id_seq.nextval from (select 11111, 'text', 'text', 'text', NULL, 'text', 'text', 'text', '?', 'text' from dual union all select 11111, 'text', 'text', 'text', NULL, 'text', NULL, NULL, '?', 'text' from dual) tt; 产生错误 00918. 00000 - "column ambiguously defined 引用第一行。
    • @yPennylane - 尝试为列设置别名,如下所示:insert into a_glw select tt.*, work_id_seq.nextval from (select 11111 col1, 'text' col2, 'text' col3, 'text' col4, NULL col5, 'text' col6, 'text' col7, 'text' col8, '?' col9, 'text' col10 from dual union all select 11111, 'text', 'text', 'text', NULL, 'text', NULL, NULL, '?', 'text' from dual) tt
    • 我发现,我不允许将相同的文本放在一个 select 语句的 2 列中。我不明白为什么。
    • 它不起作用。现在出现错误01722. 00000 - "invalid number"
    • 那么解决办法是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2014-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    相关资源
    最近更新 更多