简体   繁体   English

使用select from dual插入数据的区别

[英]difference in inserting data using select from dual

what is the difference with both query ? 两个查询有什么区别? are they same ? 他们一样吗? do they give the same results ? 他们会给出相同的结果吗? I saw them in a script and I wonder if there is a difference. 我在脚本中看到它们,我想知道是否存在差异。

Query 1 :
insert into tab1 ( id , name , last ) values ( 1 , 'st' , 'ov');


Query 2 :
insert into tab1 ( id , name , last ) select 1 , 'st' , 'ov' from dual;

There is no difference in this case. 这种情况没有区别。

Using a select ... from dual for the insert can be useful in some cases (when using data from another table for example, an union , etc.), but in this case it doesn't add anything to the usual insert into . 在某些情况下(在使用来自另一个表的数据时,例如, union等),使用select ... from dual作为插入可能很有用,但在这种情况下,它不会向通常的insert into添加任何内容。

Consider this being useful: 认为这很有用:

insert
into   table_x
( col1
)
select 'a'
from   dual
union
all
select 'b'
from   dual
;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM