有一个需求是查询下面表A中的code字段的值,----------------------------------------------------------------------------------------------------------------------------------------
tableA
----------------------------------------------------------------------------------------------------------------------------------------
code | fund1 | unit1 | fund2 | unit2 | fund3 | unit3 | fund4 | unit4
----------------------------------------------------------------------------------------------------------------------------------------
BANCA01 | BANCA01 | 7 | BANCA02 | 6 | BANCA03 | 8 | BANCA04 | 5
-----------------------------------------------------------------------------------------------------------------------------------------若是code的值为'BANCA01'时将查询结果替换成后面fund也为'BANCA01'对应的unit的值,现在关键是四个fund字段中任意一个都有可能是'BANCA01',替换查询用decode还好办,但是后面这样不确定的查询,我处理不好逻辑,该怎么写才好呢,在这里恭请各位老师们帮忙指点一下迷津,学生不胜感激!
tableA
----------------------------------------------------------------------------------------------------------------------------------------
code | fund1 | unit1 | fund2 | unit2 | fund3 | unit3 | fund4 | unit4
----------------------------------------------------------------------------------------------------------------------------------------
BANCA01 | BANCA01 | 7 | BANCA02 | 6 | BANCA03 | 8 | BANCA04 | 5
-----------------------------------------------------------------------------------------------------------------------------------------若是code的值为'BANCA01'时将查询结果替换成后面fund也为'BANCA01'对应的unit的值,现在关键是四个fund字段中任意一个都有可能是'BANCA01',替换查询用decode还好办,但是后面这样不确定的查询,我处理不好逻辑,该怎么写才好呢,在这里恭请各位老师们帮忙指点一下迷津,学生不胜感激!
解决方案 »
- 备份过程中遇到如下问题。。。。。。
- 关于ORACLE8的数据库例程的问题,很奇怪,高手请进。
- oracle between and 的查询条件显示的问题
- 数据库同步老问题没解决,继续问,
- 为什么我在asp中不能和Oracle建立连接。(高分寻求答案 急急急!!!)
- 请问ORACLE中,system,sys,root,sysdba,这4种用户的默认密码是什么,如果忘记了如何找到他们,我现在就忘记了,可我都不知道怎么找到。谢
- 复制oracle后,我能用svrmgrl连接数据库,但是不能用sqlplus连接
- 用dbca创建数据库的问题!
- 我有问题!!!
- 怎样确认我是否安装了iSQL*Plus Server?
- oracle11g企业管理器如何更换数据库
- 新手求教WIN8.1装oracle 11g 碰到问题
set code =
(select unit1
from tableA h
where t.code = h.fund1
union all
select unit2
from tableA h
where t.code = h.fund2
union all
select unit3
from tableA h
where t.code = h.fund3
union all
select unit4
from tableA h
where t.code = h.fund4);
select code,(case when code=fund1 then unit1
when code=fund2 then unit2
when code=fund3 then unit3
when code=fund3 then unit4
end) new_code from tableA;
不确定你的 code是否是有重复,所以用rowid写
修改
merge into tableA a using (select rowid aaa ,code,(case when code=fund1 then unit1
when code=fund2 then unit2
when code=fund3 then unit3
when code=fund3 then unit4
end) new_code from tableA) b
on (a.rowid=b.aaa)
when matched then
update set
a.code=b.new_code;