查询的输出未按预期工作

时间:2017-11-08 16:18:35

标签: sql oracle

我使用下面的查询将列的值拆分为两列并且工作正常但是它没有按照我预期的方式工作。下面是查询以及我得到的输出。

查询:

 select distinct
 REGEXP_SUBSTR(Asset, '(.+):.+@',1,1,'i',1) as InstanceName,
 upper(REGEXP_SUBSTR(Asset, '.+@(.+)s-',1,1,'i',1)) as ServerName,
 Asset  FROM table

我得到的输出:

Servername  Instancename    Asset
HKP02LP1802 ACMHKPU1        ACMHKPU1:ACRMUTF@hkp02lp1802s-rs6000.hk.hsbc
NULL        NULL            DB2IMFI:GWISMFI@hkpb2ls0012s.hk.hsbc
NULL        NULL            DB2ICNC:CNCUSER@hkpa2ls0065s.hk.hsbc
NULL        NULL            DB2INST1:RAEC@pdb1-ctis-hase.hk.hsbc    
NULL        NULL            DB2IVIS:GWSVIS_@hkpb2ls0011s.hk.hsbc
NULL        NULL            CNW20011136\PCNISDS01@cnw20011136.hbap.adroot.hsbc
NULL        NULL            BDW00142954\PBDRMSS01@bdw00142954.hbap.adroot.hsbc
NULL        NULL            AUNSW0320015@aunsw0320015.au.hsbc
NULL        NULL            HKW00100479C02\IMPACT360@hkw00100479c02.hbap.adroot.hsbc
NULL        NULL            HKW00100430\PHKLRRS02@hkw00100430.hbap.adroot.hsbc
NULL        NULL            JPW00142975@jpw00142975.jp.hsbc
NULL        NULL            MY000LAG0005@my000lag0005.my.hsbc
NULL        NULL            BPMHKPO62@hkpa8ls0082o.hk.hsbc
NULL        NULL            PHKCECA11@hkpa8ls0132-vip.hk.hsbc
NULL        NULL            PHKDCYA1@hkp3pl0308v2-dcya1-opt-prod.hk.hsbc
NULL        NULL            PHKCTMA7@hkp3pl0408v3-ctma7-opt.hk.hsbc

我想看到的输出:

Servername      Instancename                        Asset
HKP02LP1802     ACMHKPU1                           ACMHKPU1:ACRMUTF@hkp02lp1802s-rs6000.hk.hsbc
hkpb2ls0012     DB2IMF                             DB2IMFI:GWISMFI@hkpb2ls0012s.hk.hsbc
hkpa2ls0065     DB2ICNC                            DB2ICNC:CNCUSER@hkpa2ls0065s.hk.hsbc    
pdb1-ctis-hase  DB2INST1                           DB2INST1:RAEC@pdb1-ctis-hase.hk.hsbc    
hkpb21s0011     DB2IVIS                            DB2IVIS:GWSVIS_@hkpb2ls0011s.hk.hsbc
cmw20011136     CNW20011136                        CNW20011136\PCNISDS01@cnw20011136.hbap.adroot.hsbc
db200142954     BDW00142954                        BDW00142954\PBDRMSS01@bdw00142954.hbap.adroot.hsbc
aunsw0320015    AUNSW0320015                       AUNSW0320015@aunsw0320015.au.hsbc
hkw00100479c02  HKW00100479C02                     HKW00100479C02\IMPACT360@hkw00100479c02.hbap.adroot.hsbc
hkw00100430     HKW00100430                        HKW00100430\PHKLRRS02@hkw00100430.hbap.adroot.hsbc
jpw00142975     JPW00142975                        JPW00142975@jpw00142975.jp.hsbc
my000lag0005    MY000LAG0005                       MY000LAG0005@my000lag0005.my.hsbc
hkpa8ls00082o   BPMHKPO62                          BPMHKPO62@hkpa8ls0082o.hk.hsbc
hkpa8ls0132     PHKCECA11                          PHKCECA11@hkpa8ls0132-vip.hk.hsbc
hkp3pl0308v2    PHKDCYA1                           PHKDCYA1@hkp3pl0308v2-dcya1-opt-prod.hk.hsbc
hkp3pl0408v3    PHKCTMA7                           PHKCTMA7@hkp3pl0408v3-ctma7-opt.hk.hsbc

此致

Bharath Vikas

1 个答案:

答案 0 :(得分:0)

您的某些预期输出不明确,如评论中所述。除了pdb1-ctis-hase

之外,这应该适用于所有人
SELECT DISTINCT
    regexp_substr(asset,'([^:\\@]+)[:\\@]',1,1,'i',1) AS instancename,
    upper(regexp_replace(regexp_substr(asset,'@([^\.-]+)[\.-]',1,1,'i',1),'[so]$','') ) AS servername,
    asset
FROM
    yourtable;