Home » SQL & PL/SQL » SQL & PL/SQL » REGEXP_SUBSTR (Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production)
REGEXP_SUBSTR [message #597050] Mon, 30 September 2013 10:14 Go to next message
fakru.y
Messages: 34
Registered: May 2007
Member
Hi,
I never use REGEXP_SUBSTR function which is available in SQL. i need help on below two queries

1) i need to derive the substring enclosed with (). see the example below.

Cedilla(ç)

my output should be ç which is enclosed with ()

2) i need to derive the substring from right to left until the first dot if the pattern is like below.

xxxxx.yyyyy.zzzzz.aaaa.bbbbb

my output should be bbbbb
icon8.gif  Re: REGEXP_SUBSTR [message #597051 is a reply to message #597050] Mon, 30 September 2013 10:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

In your previous topic you said you got the solution but you didn't post it when I asked you.
Why?
Don't you want to help people and just take profit from them without give anything?

Re: REGEXP_SUBSTR [message #597052 is a reply to message #597051] Mon, 30 September 2013 11:09 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Here are some options:
SQL> with test as
  2    (select 'Cecilia (x)' col from dual)
  3  select
  4    substr(col,
  5           instr(col, '(') + 1,
  6           instr(col, ')') - instr(col, '(') - 1
  7          ) oldfashioned,
  8    substr(regexp_substr(col, '\(\w+\)'),
  9           2,
 10           length(regexp_substr(col, '\(.*?\)')) - 2
 11          ) regexp_10g,
 12    regexp_substr(col, '\((\w+)\)', 1, 1, null, 1) regexp_11g
 13  from test;

OLDFASHIONED    REGEXP_10G      REGEXP_11G
--------------- --------------- ---------------
x               x               x
SQL> with test as
  2    (select 'xxx.yyy.aaa.bbb' col from dual)
  3  select
  4    regexp_substr(col, '\w+$') result
  5  from test;

RESULT
----------
bbb

SQL>

[Updated on: Mon, 30 September 2013 11:11]

Report message to a moderator

Re: REGEXP_SUBSTR [message #597063 is a reply to message #597052] Mon, 30 September 2013 12:29 Go to previous message
fakru.y
Messages: 34
Registered: May 2007
Member
Michal,
sorry for inconvinence, its not my intention, not to share the information to others. i always respect give and take method. i just forgot to share what i got it.

thanks for the solutions Mr.Littlefoot
Previous Topic: NTILE Issue
Next Topic: CASE statement
Goto Forum:
  


Current Time: Fri Apr 26 00:01:24 CDT 2024