update某个表时,如果需要和其他表关联,这样的SQL语句在ORACLE中实现起来比较呕心。各个where条件需要分别与一堆select语句嵌套使用才可,晕~~
以下sql语句是在工作中写出的,做个备忘录:

oracle关联更新-- 更新应收账款净额
oracle关联更新
update t_0303009 t1
oracle关联更新   
set t1.item_value = 
oracle关联更新(
oracle关联更新
select t2.item_value
oracle关联更新  
from
oracle关联更新       (
oracle关联更新            
SELECT   a.product_id, a.item_id, b.item_value
oracle关联更新                
FROM (SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%011') a,
oracle关联更新                     (
SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%008') b
oracle关联更新               
WHERE a.product_id = b.product_id
oracle关联更新                 
AND SUBSTR (a.item_id, 26= SUBSTR (b.item_id, 26)
oracle关联更新                 
AND a.item_value = 0
oracle关联更新     ) t2
oracle关联更新
where t1.product_id = t2.product_id
oracle关联更新  
and t1.item_id = t2.item_id
oracle关联更新)
oracle关联更新
where t1.product_id = ( select product_id from 
oracle关联更新       (
oracle关联更新            
SELECT   a.product_id, a.item_id, b.item_value
oracle关联更新                
FROM (SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%011') a,
oracle关联更新                     (
SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%008') b
oracle关联更新               
WHERE a.product_id = b.product_id
oracle关联更新                 
AND SUBSTR (a.item_id, 26= SUBSTR (b.item_id, 26)
oracle关联更新                 
AND a.item_value = 0
oracle关联更新     ) jj
oracle关联更新     
where t1.product_id = jj.product_id
oracle关联更新       
and t1.item_id = jj.item_id
oracle关联更新     )
oracle关联更新
and t1.item_id = ( select item_id from 
oracle关联更新       (
oracle关联更新            
SELECT   a.product_id, a.item_id, b.item_value
oracle关联更新                
FROM (SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%011') a,
oracle关联更新                     (
SELECT product_id, item_id, item_value
oracle关联更新                        
FROM t_0303009
oracle关联更新                       
WHERE item_id LIKE 'B%008') b
oracle关联更新               
WHERE a.product_id = b.product_id
oracle关联更新                 
AND SUBSTR (a.item_id, 26= SUBSTR (b.item_id, 26)
oracle关联更新                 
AND a.item_value = 0
oracle关联更新                     ) jj2
oracle关联更新                     
where t1.product_id = jj2.product_id
oracle关联更新                       
and t1.item_id = jj2.item_id
oracle关联更新 )
oracle关联更新

 

 

相关文章: