在修改查询时需要一些帮助

时间:2017-12-04 10:55:51

标签: oracle

我使用以下查询将值拆分为另一列,下面是我得到的输出。

查询:

select distinct custom_attributes, REPLACE(REGEXP_SUBSTR (custom_attributes, 'LastChange=[0-9]{4}\/[0-9]{2}\/[0-9]{2}'), 'LastChange=', '') 
as dates1 from table_name ;

输出:

custom_attributes                                                                                                                                                                                  dates1
Attributes: assetGroup=USVHILVSQL020\MSSQL_01; DBTimeStamp=2017/09/17; GSDServiceCount=1;  HSBCLocation=US Vernon Hills; DBCount=7; Environment=LIVE; LastChange=2017/09/17                      2017/09/17 
Attributes: BusinessCriticality=TIER 2; Environment=LIVE; ViewPointName=DBA HTSA - DB2;  DBTimeStamp=9/16/2017; GSDServiceCount=1; LastChange=9/17/2017 20:00                                        NULL
Attributes: ServerId=100010000401; GSDServiceCount=0; Environment=LIVE; LastChange=16/11/2016 09:00;                                                                                                 NULL
ServerStatus=ACTIVE; CountryCode=TR; HSBCLocation=TR Istanbul Esentepe
Attributes: GSDServiceCount=0; CountryCode=MX; ServerId=100010000301; Environment=LIVE; ServerStatus=ACTIVE;                                                                                         NULL
LastChange=10/7/2017 9:00; HSBCLocation=MX Chapultepec 

必需输出:

custom_attributes                                                                                                                                                                                  dates1
Attributes: assetGroup=USVHILVSQL020\MSSQL_01; DBTimeStamp=2017/09/17; GSDServiceCount=1;  HSBCLocation=US Vernon Hills; DBCount=7; Environment=LIVE; LastChange=2017/09/17                      2017/09/17 
Attributes: BusinessCriticality=TIER 2; Environment=LIVE; ViewPointName=DBA HTSA - DB2;  DBTimeStamp=9/16/2017; GSDServiceCount=1; LastChange=9/17/2017 20:00                                    9/17/2017
Attributes: ServerId=100010000401; GSDServiceCount=0; Environment=LIVE; LastChange=16/11/2016 09:00;                                                                                             16/11/2016 
ServerStatus=ACTIVE; CountryCode=TR; HSBCLocation=TR Istanbul Esentepe
Attributes: GSDServiceCount=0; CountryCode=MX; ServerId=100010000301; Environment=LIVE; ServerStatus=ACTIVE;                                                                                     10/7/2017 
LastChange=10/7/2017 9:00; HSBCLocation=MX Chapultepec

1 个答案:

答案 0 :(得分:0)

改为使用instrsubstr

select distinct custom_attributes, 
substr( custom_attributes, instr(custom_attributes, 'LastChange=')+11, 10) 
as dates1 from table_name ;