今天凌晨因为要在数据库里做一些操作,是关于两表关联的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
)
新闻热点
疑难解答