SQL

全部插入并插入,nextval不适用于重复值

发布于 2021-07-06 11:30:11

我想insert into使用Oracle SQL在一条语句内的表中插入2行。

此代码有效:

insert into a_glw select tt.*, work_id_seq.nextval from 
    (select 11111, 'one text', 12345, 'new text', NULL, 
    'some text', 'nice text', 'test', 'text', 'great text' 
    from dual 
union all 
    select 11111, 'one text', 12345, 'new text', NULL, 
    'some text', 'nice text', 'test', 'text', 'great text' 
    from dual) tt;

当我改变的值testtext这个代码产生错误00918. 00000 - "column ambiguously defined"

insert into a_glw select tt.*, work_id_seq.nextval from 
    (select 11111, 'one text', 12345, 'new text', NULL, 
    'some text', 'nice text', 'text', 'text', 'great text' 
    from dual 
union all 
    select 11111, 'one text', 12345, 'new text', NULL, 
    'some text', 'nice text', 'test', 'text', 'great text' 
    from dual) tt;

在一个select语句中插入相同的值似乎是一个问题。我怎样才能解决这个问题?

关注者
0
被浏览
113
1 个回答
  • 面试哥
    面试哥 2021-07-06
    为面试而生,有面试问题,就找面试哥。

    由于第二个示例中的值不同,因此必须具有用于列的别名才能执行insert语句。

    在第一个示例中,test是列值,test由于您未提供别名,因此它假定为默认列名。

    看到这里的例子

    如果查看附带的屏幕快照,第二个示例是将TEXT列重复两次,因为select语句将列值视为列名,因此必须为列提供别名。



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看