oracle中update语句更新字段

您所在的位置:网站首页 数据库更新一个字段的一个数据 oracle中update语句更新字段

oracle中update语句更新字段

2024-07-02 10:19| 来源: 网络整理| 查看: 265

如需要修改下列数据:表名为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'), '上海市浦东新区');

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3