日期:2014-05-17  浏览次数:20810 次

在线急等谢谢先!
现在有这样的一对数据
表A
name address
123456 jlkjsdilmdskl
987654 sadsaff
456789 afdfdsfds


表B
name
12345
98765
45678

我想把表A 通过表B的name值 中的name截取出来就剩
name
6
4
9


用什么办法好呢。。数据有数万条。。必须要这么截才行。

------解决方案--------------------
with a as
 (select 123456 name, 'jlkjsdilmdskl' adress
from dual
union all
select 987654, 'sadsaff'
from dual
union all
select 456789, 'afdfdsfds' from dual),
b as
 (select 12345 name
from dual
union all
select 98765 name
from dual
union all
select 45678 name from dual)
select replace(name, subname)
from (select t.name, t1.name as subname, instr(t.name, t1.name) as cn
from a t, b t1)
 where cn = 1
------解决方案--------------------
select replace(name, subname) as name,decode(translate(replace(name, subname),'0123456789',''),'',1,0) as is_num
from (select t.name, t1.name as subname, instr(t.name, t1.name) as cn
from a t, b t1)
 where cn = 1