请问一个oracle的问题

来源:百度知道 编辑:UC知道 时间:2024/05/14 21:12:57
ID NAME
1 1
2 1
3 1
4 2
5 2
6 2
7 3
8 3
9 3

请问我想实现 把NAME=2 的 3个ID 从最小的开始 4改成-1 5改成-5 6 改成-3

请问这个应该怎么实现呢 谢谢
.......... 不是的 我要改ID 字段 根据NAME 来改
这样写死的我也会的 但是现在的情况是 活的不能这样写死的
请问能有别的办法吗,加上游标呢 至少给我点思路吧
我这里只是举个例子 实际应用的时候并不是NAME字段 有实际意义的 不然我也不会问啦 继续拜托大家

update table set id=-1 where id=4;
update table set id=-5 where id=5;
update table set id=-3 where id=6;
commit;

单凭SQL语句是不可能。
update本是批量操作,没有判断功能,
只能通过pl/sql程序块或者编程语言来控制。

create sequence id_seq
start with -1
increase by -2
minvalue -5;

update table t1 set id=id_seq.nextvalue where id in (select id
from table t2
where name=2 and t1.id=t2.id);

以上代码只是设想。

你后面的name不都一样的吗,先后改有什么意义吗?