在格式化查询时需要一些帮助

时间:2017-11-10 18:10:21

标签: sql oracle

在修改以下查询时寻求帮助,

查询:

select distinct 
      upper(
        regexp_replace(
          regexp_substr(asset,'@([^\.-]+)[so]?[\.-]',1,1,'i',1)
          ,'[so]$','')
      ) AS instancename,
      Asset 
    from hsbc_csmip_dbprotect

当前输出:

Asset                                   |Instancename
----------------------------------------+------------
EMS                                     |   NULL
IGASDBL_11G                             |   NULL
IGASHLEL_11G                            |   NULL
LMSPEGA1@SSUML527                       |   NULL
ABACOGP@abacogp@ora-abacogp.de.hsbc     |ABACOGP@ORA
ABM00@frlooraprda1.systems.uk.hsbc      |FRLOORAPRDA1
ABMHIST@trabmora01h.hbtr.adroot.hsbc    |TRABMORA01H

期望的输出:

Asset                                   |Instancename
----------------------------------------+------------
EMS                                     |EMS
IGASDBL_11G                             |IGASDBL
IGASHLEL_11G                            |IGASHLEL
LMSPEGA1@SSUML527                       |SSUML527
ABACOGP@abacogp@ora-abacogp.de.hsbc     |ABACOGP
ABM00@frlooraprda1.systems.uk.hsbc      |FRLOORAPRDA1
ABMHIST@trabmora01h.hbtr.adroot.hsbc    |TRABMORA01H

1 个答案:

答案 0 :(得分:0)

检查是否有效:

 select distinct upper(regexp_substr(SUBSTR(asset, INSTR(asset, '@')+1),'[^-@\.]+',1,1)) AS instancename,Asset 
from hsbc_csmip_dbprotect;