比如有个表meta_cust中有c_cust_id和c_cust_name、c_state三个字段,有以下4条记录:
c_cust_id c_cust_name c_state
001 aaa 1
002 bbb 1
001 2
002 2
就是说后面两条记录中的c_cust_name字段为空,怎样才能把后面这两条记录的c_cust_name字段改成和上面的一致。我这样写的SQL语句没有任何反应:update meta_cust a set a.c_cust_name =
(select b.c_cust_name from meta_cust b
where b.c_cust_name is not null
and a.c_cust_id = b.c_cust_id )
where a.c_cust_name is null
c_cust_id c_cust_name c_state
001 aaa 1
002 bbb 1
001 2
002 2
就是说后面两条记录中的c_cust_name字段为空,怎样才能把后面这两条记录的c_cust_name字段改成和上面的一致。我这样写的SQL语句没有任何反应:update meta_cust a set a.c_cust_name =
(select b.c_cust_name from meta_cust b
where b.c_cust_name is not null
and a.c_cust_id = b.c_cust_id )
where a.c_cust_name is null
确实是有这样的情况,但是即使加上distinct 或者rownum=1也不起作用。
update meta_cust a set a.c_cust_name =
(select distinct b.c_cust_name from meta_cust b
where b.c_cust_name is not null
and a.c_cust_id = b.c_cust_id )
where a.c_cust_name is null
update meta_cust a set a.c_cust_name =
(select b.c_cust_name from meta_cust b
where b.c_cust_name is not null
and a.c_cust_id = b.c_cust_id and rownum=1 )
where a.c_cust_name is null
没有反应的意思是一条记录也没有更改,语句运行正常。我看了记录还是空的,肯定是NULL。
每次执行后都commit过的。
每次执行后都commit过的。
这里没有环境,回去测试一下。或者你可以给我一个可以连接的测试环境吗?
isqlplus也可以呀。
随便新建一个表。
看来问题出在表上面,会不会是锁的问题?
个人认为不是这个问题。赫赫。
直接在sqlplus里面调用sql语句的?
这样的话,有点奇怪呢。赫赫。除了没有commit的话,目前还找不出理由。嗬嗬,不是怀疑你的做法,我也想知道为什么会出现这个状况,赫赫。避免以后再遇到同样的问题。
查看了没有被锁住。