ITeye博客

update的其它用法

icyheart · 2009-07-02 13:52 · Oracle · 企业架构 · Markdown

Update除了有基本的语法格式外还有其它的一些常用的格式:

(1)、更新数据为内部变量或者函数,格式为:

    update 表名

    set 字段名1=函数1[…,字段名n=函数n]

    [where 条件]

    eg:

update student

       set sbirth=getdata()

       where sno=’990001’

(2)、更新数据为同一记录的其他字段值(将一张表中的同一记录的某个字段值改成另一字段的值),格式为:

    update 表名

    set 字段名1=字段名m[…,字段名m=字段名n]

    from 表名1,表名2

    [where 条件]

eg:  

           update student

set sdept=stu.sname

from student,student as stu

where student.sno='990001'

(3)、更新数据为不同表的字段值,该方式要求更新数据的目标表和源表有相同的字段(将一个表中字段的值赋给另一个表的某个字段),格式为:

    update 表名1

set 表名1.字段名1=表名2.字段名1[...,表名1.字段名n=表名2.字段名n]

from 表名1,表名2

[where 条件]

eg:

      update student

set sdept=stu.sdept

from student,stu

where student.sno='990001' and stu.sno='990002'

(4)、更新数据为同一个表中的某些字段值(将一个表中不同记录之间的字段值进行替换),格式为:

    update 表名1

set 表名1.字段名1=表别名.字段名1[...表名1.字段名n=表别名.字段名n]

from 表名1,表名 as 别名

[where 条件]

eg:

           update student

set sdept=stu.sdept

from student,student as stu

where student.sno='990001' and stu.sno='990002'

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。