Discuz!NT
欢迎 游客 , 注册 | 登录 | 会员 | 界面 | 简洁版本 | 在线 | 帮助
商都网教育宝典宝库

发表新主题 回复该主题
本主题被查看511次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第   上一主题   下一主题
标题: 两表(多表)关联update的写法
-[尕硴]
超级版主
UID: 71
来自:
精华: 130
积分: 14003
帖子: 12909
注册: 2007-10-22 17:59:00
状态: 离线
威望: 444.00
金钱: 3355.00 元
只看楼主 2008-03-11 14:37
两表(多表)关联update的写法
因为要在数据库里做一些操作,是关于两表关联的update,但语句怎么写都不正确,老是报错,于是心惊肉跳(就怕不能及时完成操作)去查了一下,NND,原来把SQL写成了在SQL Server下面的特有形式,这种语法在Oracle下面是行不通的,急忙改回来,及时完成了任务。顺便也把查到的SQL帖出来,哪天再忘记了,也好在这里找回来:

  update customers a
  set    city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)
  where  exists (select 1
                  from  tmp_cust_city b
                  where  b.customer_id=a.customer_id
                )

  -- update 超过2个值
  update customers a 
  set    (city_name,customer_type)=(select b.city_name,b.customer_type
                                    from  tmp_cust_city b
                                    where  b.customer_id=a.customer_id)
  where  exists (select 1
                  from  tmp_cust_city b
                  where  b.customer_id=a.customer_id
                )
#1  
发表新主题 回复该主题
本主题被查看511次, 共1个帖子, 1页, 当前为第1页     选择页数: 1      跳转到第







现在的时间是 2008-10-16 13:06:22

版权所有 商都网教育宝典
         Powered by Discuz!NT 1.0.6666    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.032 seconds