要插入的相同行到表我使用插入和更新同时
Insert into table (select * from table where columnA = 'a' and columnB = 'b')
我是能够插入和更改columnB =“C”在一个SQL?
要插入的相同行到表我使用插入和更新同时
Insert into table (select * from table where columnA = 'a' and columnB = 'b')
我是能够插入和更改columnB =“C”在一个SQL?
是的,只是在选择指定的值:
insert into table (ColumnA, ColumnB)
select ColumnA, 'c'
from table
where columnA = 'a' and columnB = 'b'
(如果你有更多的列,只需添加它们在列列表和选择,就像ColumnA)
我有60列是否必须包含在列表中? – 2012-08-10 10:12:11
@JonathanChan是的,你这样做。考虑对[USER_TAB_COLUMNS](http://docs.oracle.com/cd/B13789_01/server.101/b10755/statviews_2656.htm)使用select来为您构建查询(或至少列列表)。另一种方法是在插入后更新表格,并且在此之后才进行提交(但是我怀疑你已经知道了)。 – derobert 2012-08-10 10:14:21
@jonathan:有你试过这个吗? – 2012-08-10 10:04:47
我的表格有60列。只有1列需要更改为不同的值。 – 2012-08-10 10:05:02
@Gaurav Soni是的,我已经运行它。它的作品,但我不知道如何插入和更新到新行。 – 2012-08-10 10:06:23