要插入的相同行到表我使用插入和更新同時
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