Skip to main content

How to get string between parenthesis?

  • Dec 9, 2017 3:25 PM UTC
  • 2 replies
  • 13 views

Abhi1540

Hi Experts,
I have a string between 2 parenthesis. how to get the string between 2 parenthesis as follows

my input is: (success)

output will be only success

how can i achieve this??

2 replies

marcothesane
Forum|alt.badge.img+1
  • Participating Frequently
  • Dec 9, 2017 3:41 PM UTC

WITH input(s) AS (SELECT '(success)' )
SELECT REPLACE(REPLACE(s,'(',''),')','') FROM input;


Jim_Knicely
Forum|alt.badge.img+2
  • Participating Frequently
  • Dec 10, 2017 11:15 PM UTC

You can also use the TRANSLATE function:

dbadmin=> select translate('(success)', '()', '') "What's inside the Parentheses?";
 What's inside the Parentheses?
--------------------------------
 success
(1 row)

See:
https://my.vertica.com/docs/9.0.x/HTML/index.htm#Authoring/SQLReferenceManual/Functions/String/TRANSLATE.htm