oracle关联更新
2007-12-15 00:23
330 查看
update某个表时,如果需要和其他表关联,这样的SQL语句在ORACLE中实现起来比较呕心。各个where条件需要分别与一堆select语句嵌套使用才可,晕~~
以下sql语句是在工作中写出的,做个备忘录:
-- 更新应收账款净额
update t_0303009 t1
set t1.item_value =
(
select t2.item_value
from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) t2
where t1.product_id = t2.product_id
and t1.item_id = t2.item_id
)
where t1.product_id = ( select product_id from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) jj
where t1.product_id = jj.product_id
and t1.item_id = jj.item_id
)
and t1.item_id = ( select item_id from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) jj2
where t1.product_id = jj2.product_id
and t1.item_id = jj2.item_id
)
以下sql语句是在工作中写出的,做个备忘录:
-- 更新应收账款净额
update t_0303009 t1
set t1.item_value =
(
select t2.item_value
from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) t2
where t1.product_id = t2.product_id
and t1.item_id = t2.item_id
)
where t1.product_id = ( select product_id from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) jj
where t1.product_id = jj.product_id
and t1.item_id = jj.item_id
)
and t1.item_id = ( select item_id from
(
SELECT a.product_id, a.item_id, b.item_value
FROM (SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%011') a,
(SELECT product_id, item_id, item_value
FROM t_0303009
WHERE item_id LIKE 'B%008') b
WHERE a.product_id = b.product_id
AND SUBSTR (a.item_id, 2, 6) = SUBSTR (b.item_id, 2, 6)
AND a.item_value = 0
) jj2
where t1.product_id = jj2.product_id
and t1.item_id = jj2.item_id
)
相关文章推荐
- Oracle 2张表关联更新
- Oracle 两个关联表之间更新
- oracle 实现 关联两个表更新 update select
- oracle 9i 中的关联更新跟oracle10g的区别
- oracle 多表关联 更新
- oracle 多表关联更新,需要更新的字段在另一个表里
- [ORACLE]关联表更新数据
- Oracle 两个关联表之间更新
- Oracle多表关联更新的方式选择
- oracle与sql两表关联更新
- 【Oracle】两个表Join关联更新
- Oracle 2张表关联更新表信息的四个SQL
- Oracle多表关联更新
- 对于oracle两表关联更新的问题解决办法
- 关于 oracle 多表关联更新的语句写法——仅仅是给自己看的
- oracle 多表关联更新为什么要加exists
- Oracle多表关联更新(update多表关联)
- oracle 多表关联更新语句
- Oracle 中两表关联进行更新
- oracle UPDATE 多表关联更新