我正在使用以下查询以将'@'替换为' - '并输出如下输出。
select upper(replace(replace(software_module_component_name,'DBSM:',''),'@','-')) as Test from SOFTWARE_MODULE
where software_module_component_name like 'DBSM:PUKEIM%'
Test
PUKEIMA1-GBL05266-ORACLE - V11.2.0.4
PUKEIMA1-GBL05267-IBM - V11.2.0.4
PUKEIMA1-GBL05268-INTEL - V11.2.0.4
但我希望看到输出如下。
Test
PUKEIMA1-GBL05266
PUKEIMA1-GBL05267
PUKEIMA1-GBL05268
此致 Bharath Vikas
答案 0 :(得分:0)
由于输出看起来是对称的,因此您可以使用SUBSTR
并修复SUBSTR
字符。请尝试:
SELECT SUBSTR (
UPPER (
REPLACE (REPLACE (software_module_component_name, 'DBSM:', ''),
'@',
'-')),
1,
17)
AS Test
FROM SOFTWARE_MODULE
WHERE software_module_component_name LIKE 'DBSM:PUKEIM%'
你可以这样做:
WITH tbl (str)
AS (SELECT 'PUKEIMA1-GBL05266-ORACLE - V11.2.0.4' FROM DUAL
UNION ALL
SELECT 'PUKEIMA1-GBL05267-IBM - V11.2.0.4' FROM DUAL
UNION ALL
SELECT 'PUKEIMA1-GBL05268-INTEL - V11.2.0.4' FROM DUAL)
--Actual query
SELECT REGEXP_SUBSTR (str,
'[^-]+',
1,
1)
|| REGEXP_SUBSTR (str,
'(.*?)([^-]+)',
1,
2)
AS
FROM tbl