有两张表cigi和cimb,
cigi结构:
-------------------------
date status segment1
--------------------------
2010 new k1
2010 new k2
2010 new k3
cimb机构:
--------------------------
date gl_code k_code
--------------------------
2010 gl1 k1
2010 gl2 k2两张表通过segment和k_code关联,
现在要将第一张表cigi的segment1字段换成cimb的gl_code相应字段
第二张表cimb不存在数据就不用更新。
cigi结构:
-------------------------
date status segment1
--------------------------
2010 new k1
2010 new k2
2010 new k3
cimb机构:
--------------------------
date gl_code k_code
--------------------------
2010 gl1 k1
2010 gl2 k2两张表通过segment和k_code关联,
现在要将第一张表cigi的segment1字段换成cimb的gl_code相应字段
第二张表cimb不存在数据就不用更新。
解决方案 »
- package body "system.emp_package" has errors
- ORACLE 数据文件为裸设备,自动扩展后是否会超过添加数据文件时设置的容量大小?
- 求教以下代码
- 请教有关PL/SQL游标的一个问题,谢谢!
- oracle
- 用C++操作ORACLE的例子
- sybase中语句转换成oracle
- 如何实现ORACLE象SQLSERVER一样实现INT的自动加一的功能??
- 用SQL语句怎么的到一个用户的所有表名?
- Oracle有没有类似于SQL SERVER的MS Profiler监视器的工具?可以监视操作后台的sql语句。
- pl/sql存储过程报错
- 嵌套事务commit和rollback分析
--------- --- -----
2010 new k1
2010 new k2
2010 new k3select * from cimb; date GL_ K_
---------- --- --
2010 gl1 k1
2010 gl2 k2update cigi set segment1=(select gl_code from cimb where cimb.k_code=cigi.segment1)
where exists(select 1 from cimb where cigi.segment1=cimb.k_code);SQL> select * from cigi; date STA SEGME
---------- --- -----
2010 new gl1
2010 new gl2
2010 new k3
我用的是的oracle11g
--如果是对应多个gl_code你需要选择哪个?update cigi set
segment1=(select gl_code,row_number(order by gl_code) rn
from cimb where cimb.k_code=cigi.segment1 and rn=1)
where exists(select 1 from cimb where cigi.segment1=cimb.k_code);
update cigi
set segment1 = (SELECT gl_code FROM cimb WHERE k_code = cigi.segment1)
where segment1 in (select k_code from cimb);----排除cimb不存在数据的情况
commit;这个可以