We're taking a break this week as Connor and Chris will both be at CloudWorld, the premier Oracle conference of 2024. If you're in Vegas, please come say Hi or pop into our sessions
Thanks for the question, Anders.
Asked: April 07, 2021 - 4:52 am UTC
Last updated: May 25, 2023 - 12:55 pm UTC
Version: 11.2.0.4
Viewed 10K+ times! This question is
SELECT REGEXP_REPLACE ( REGEXP_REPLACE ( REGEXP_REPLACE ( REGEXP_SUBSTR ( UPPER ( '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = lxc01-vip.test.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = lxc02-vip.test.com)(PORT = 1521)) (LOAD_BALANCE = ON) (FAILOVER = ON) ) (CONNECT_DATA = (SERVICE_NAME = Test) ) )'), '((HOST|HOSTNAME)[[:space:]]*(\=)[[:space:]]*(\w+|\-|\_)*(\.\w+)*|(\w+|\-|\_)*(\.\w+)+|((\w+|\-|\_)+$))'), ' ', ''), 'HOST=', ''), 'HOSTNAME=', '') HOSTNAME FROM DUAL;
Rajeshwaran Jeyabal, April 08, 2021 - 2:47 pm UTC
demo@XEPDB1> variable x varchar2(300) demo@XEPDB1> exec :x := '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = lxc01-vip.test.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = lxc02-vip.test.com)(PORT = 1521)) (LOAD_BALANCE = ON) (FAILOVER = ON) ) (CONN ECT_DATA = (SERVICE_NAME = Test) ) ))' PL/SQL procedure successfully completed. demo@XEPDB1> demo@XEPDB1> col x for a25 demo@XEPDB1> select regexp_substr( :x,'HOST = (\S+)\)',1,level,'i',1) x 2 from dual 3 connect by level <= regexp_count(:x,'HOST = \S+\)'); X ------------------------- lxc01-vip.test.com lxc02-vip.test.com demo@XEPDB1>
demo@XEPDB1> select listagg(x,' ') within group( order by n) x 2 from ( 3 select regexp_substr( :x,'HOST = (\S+)\)',1,level,'i',1) x,level n 4 from dual 5 connect by level <= regexp_count(:x,'HOST = \S+\)') 6 ) 7 / X -------------------------------------------------- lxc01-vip.test.com lxc02-vip.test.com
A reader, May 25, 2023 - 6:09 am UTC
select regexp_substr ( 'myhostname.somewhere.env.com', '^[^.]+' ) host from dual; HOST ---------- myhostname
Check out more PL/SQL tutorials on our LiveSQL tool.
PL/SQL reference manual from the Oracle documentation library