前几天用到Oracle数据库的update更新,对于这个简单问题,却出现了不少问题,所以现将从网上搜索资料及自已的总结罗列在此以备一时之用.
以下所列sql都是基于下表
create table test (name varchar2(30),code varchar2(10),i_d varchar2(10));
插入数据
insert into test(name,code,i_d) values('zhu1','001','1');
insert into test(name,code,i_d) values('zhu2','002','2');
insert into test(name,code,i_d) values('zhu3','003','3');
commit;
select * from test s;
1. update 更新i_d为1的数据
--方式1
update test set name='zhurhyme1',
code='007' where i_d='1';
commit;
这样可以成功
--方式2
update test set (name,code)=(
'zhurhyme2','007')
where i_d='1';
注意,这样是不行,update set 必须为子查询,所以需要将其改为 :
--方式3
update test set