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

字段中部分字符进行替换(急!)
现有表table1和table2
table1表中有4个字段:id,A端,Z端,波道电路
id A端 Z端 波道电路
111205102339182399 OuHaiBian_CW_S_015/shelf1/s1/p7-8/A TangLingBian_CW_S_013/s17/p7-8/B MSTP-10G-TaiZhou-WenZhou-58.98,MSTP-10G-TangLingBian-OuHaiBian-60.61,MSTP-10G-TaiZhou-WenZhou-59.79
……
table2是关于table1表中A端,Z端,波道电路的拼音汉子对应表;
station 局站
OuHaiBian 瓯海变
TangLingBian 塘岭变
……

现在要将table1表中的拼音全部转换成汉子,怎么实现?

------解决方案--------------------
--手工置顶,期待高手,用REGEXP_REPLACE也无法做到自由变通,期待高手,或许写个过程能实现
SELECT REGEXP_REPLACE('OuHaiBian_CW_S_015/shelf1/s1/p7-8/A','[a-zA-Z]{5,}Bian','瓯海变电站') FROM DUAL;
SELECT REGEXP_REPLACE('TangLingBian_CW_S_013/s17/p7-8/B','[a-zA-Z]{8,}Bian','塘岭变电站') FROM DUAL;
SELECT REGEXP_REPLACE('MSTP-10G-TaiZhou-WenZhou-58.98,MSTP-10G-TangLingBian-OuHaiBian-60.61,MSTP-10G-TaiZhou-WenZhou-59.79','[a-zA-Z]{8,}Bian','塘岭变电站') FROM DUAL;



REGEXP_REPLACE('OUHAIBIAN_CW_S_015/SHELF1/S1/P7-8/A','[A-ZA-Z]{5,}BIAN','瓯海变电站') 
-------------------------------------------- 
瓯海变电站_CW_S_015/shelf1/s1/p7-8/A

REGEXP_REPLACE('TANGLINGBIAN_CW_S_013/S17/P7-8/B','[A-ZA-Z]{8,}BIAN','塘岭变电站') 
----------------------------------------- 
塘岭变电站_CW_S_013/s17/p7-8/B

REGEXP_REPLACE('MSTP-10G-TAIZHOU-WENZHOU-58.98,MSTP-10G-TANGLINGBIAN-OUHAIBIAN-60.61,MSTP-10G-TAIZHOU-WENZHOU-59.79','[A-ZA-Z]{8,}BIAN','塘岭变电站') 
------------------------------------------------------------------------ 
MSTP-10G-TaiZhou-WenZhou-58.98,MSTP-10G-塘岭变电站-OuHaiBian-60.61,MSTP-10G-TaiZhou-WenZhou-59.79
------解决方案--------------------
对啊...所以联合table1 和 table2一起查询,后面的条件 instr(t1.A端,t2.拼音) > 0 表示字符串里面包含有这个拼音...
如果有多个...那还真没什么好办法,只能多层嵌套一下...但是如果你要的是update语句的话,可以多执行几次..那就能全部替换了..