sql – Oracle:更新一个字段时复制行

请注意:我问我要回答的问题.我知道这个问题意味着数据库设置不好.所以我会投票反对任何建议改变表格设置方式的答案.

我需要复制一堆行,同时更改一个值.

name   col1 col2
dave   a    nil
sue    b    nil
sam    c    5

需要成为:

name   col1 col2
dave   a    nil
dave   a    a
sue    b    nil
sue    b    a
same   c    5

IE表中col2为null的表中的所有条目,在表中复制名称和col1时创建一个新条目,col2为a.

解决方法

使用:
INSERT INTO table
  (name,col1,col2)
SELECT t.name,t.col1,'a'
  FROM TABLE t
 WHERE t.col2 IS NULL

这是假设名称或col1列都不是主键,或者两者都有唯一约束.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...