oracle中update语句修改多个字段


如需要修改下列数据:表名为student

 

 

 

一般会这样写:

update student
set sname = '李四',
sage = 20,
sbirthday = to_date('2010-01-01', 'yyyy-mm-dd'),
saddress = '广州市越秀区'
where sid = 1;

  


如果字段非常多,这样写就稍微麻烦点,因为待修改字段和待修改的数据没有分离。

还有另外一种写法(字段多的时候写的时候方便,书写效率高些;字段少的时候感觉不出来):

update student
set (sname, sage, sbirthday, saddress) =
(select '李四', 20, to_date('2010-01-01', 'yyyy-mm-dd'), '广州市越秀区' from dual)
where sid = 1;

  


附注:

student表

create table STUDENT
(
sid NUMBER,
sname VARCHAR2(40),
sage NUMBER,
sbirthday DATE,
saddress VARCHAR2(200)
);

  

数据

insert into student (sid, sname, sage, sbirthday, saddress)
values (1, '张三', 10, to_date('1994-01-01', 'yyyy-mm-dd'), '上海市浦东新区');

  




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM