求助一个批量更新的sql语句如何写
数据库是oracle
表tableA A,表tableB B都存在字段
product_name(产品名称);consign_id(单号)
表A中另外存在vol(总体积);qty(产品数量)
表B中另外存在unit_vol(产品单位体积)
要求批量更新vol的值,条件是A.product_name=B.product_name and A.consign_id=B.consign_id
并且A.vol=A.qty*B.unit_vol
update语句应该怎么写?
数据库是oracle
表tableA A,表tableB B都存在字段
product_name(产品名称);consign_id(单号)
表A中另外存在vol(总体积);qty(产品数量)
表B中另外存在unit_vol(产品单位体积)
要求批量更新vol的值,条件是A.product_name=B.product_name and A.consign_id=B.consign_id
并且A.vol=A.qty*B.unit_vol
update语句应该怎么写?
解决方案 »
- trunc日期会影响索引的使用吗?
- oracle 9i for linux:怎么完全删除创建的一个数据库.
- 100分求解决oracle汉字乱码问题!!!
- 求一道PL/SQL函数问题!
- oracle一个奇怪的问题
- oracle,什么才算真正的了解你
- 数据库如何恢复!快快
- Oracel CD 清单,请大侠帮忙看看都是些什么东东?
- 在ORACLE中能调用其它数据库的存储过程吗?
- oracle 存储过程调用webservice 取不到返回的参数
- Oracle中如何编写通过Databaselink得到的sequence?
- 我定义一个每天凌晨4点中执行的任务,中间关闭数据库,于某一日的中午12点重新打开数据库,这个任务如何执行?
A.product_name=B.product_name and A.consign_id=B.consign_id)
where exists(select 1 from a,b
A.product_name=B.product_name and A.consign_id=B.consign_id)
SQL codeupdate A set A.vol=( select A.qty*B.unit_vol from a,b
A.product_name=B.product_name and A.consign_id=B.consign_id)
where exists(select 1 from a,b
A.product_name=B.product_name and A.consign_id=B.consign_id)
update tableA a set
vol=A.qty*(select distinct unit_vol from tableB where a.consign_id=b.consign_id)
where exists (select 1 from tableB where a.consign_id=b.consign_id);
set vol= A.qty*(select B.unit_vol from tableB B where A.product_name=B.product_name and A.consign_id=B.consign_id)
where exists(select 1 from tableB where product_name=B.product_name and consign_id=B.consign_id)
SQL> SELECT * FROM A;PRODUCT_NAME CONSIGN_ID VOL QTY
-------------------- --------------------------------------- --------------------------------------- ---------------------------------------
A 1 10 10
B 2 5 10
C 3 2 10
D 4 8 8SQL> SELECT * FROM B;PRODUCT_NAME CONSIGN_ID UNIT_VOL
-------------------- --------------------------------------- ---------------------------------------
A 1 10
B 2 8
C 3 6SQL>
SQL> UPDATE A SET A.VOL=(
2 SELECT A.QTY*unit_vol FROM B
3 WHERE A.product_name=B.product_name
4 and A.consign_id=B.consign_id
5 );4 rows updatedSQL> SELECT * FROM A;PRODUCT_NAME CONSIGN_ID VOL QTY
-------------------- --------------------------------------- --------------------------------------- ---------------------------------------
A 1 100 10
B 2 80 10
C 3 60 10
D 4 8SQL>
set vol= A.qty*(select B.unit_vol from co_consign_order_detail B ,ic_warehouse_inventory A where A.product_name = B.product_name and A.consign_id = B.consign_id)
where exists(select 1 from co_consign_order_detail B,ic_warehouse_inventory A where B.product_name=B.product_name and B.consign_id=A.consign_id)执行出错
select B.unit_vol from co_consign_order_detail B ,ic_warehouse_inventory A where A.product_name = B.product_name and A.consign_id = B.consign_id
这句话会查出多个值
select a.vol vol,a.qty qty,b.unit_vol uvol from
tablea a,tableb b where a.product_name=b.product_name
and
a.consign_id=b.consign_id
) c set c.vol=c.qty*c.uvol