·一周点击排行
·热点推荐
您的位置:首页 >> 计算机 » 等级考试 » 两表(多表)关联update的写法 >> 正文

两表(多表)关联update的写法

发布时间:2008-3-11 14:37:00 浏览次数: 416

因为要在数据库里做一些操作,是关于两表关联的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
                )


讨论此主题请进>>: 两表(多表)关联update的写法