Skip to Main Content
  • Questions
  • Removing # from the columns returned by regexp_substr

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Subhash.

Asked: September 21, 2017 - 7:46 am UTC

Last updated: September 21, 2017 - 4:13 pm UTC

Version: 12.1

Viewed 1000+ times

You Asked

Hi,

I have following sql query:

with texttab as
(
SELECT 
  ROOT_CAUSE as text
from cust_bug_data where ROOT_CAUSE is not NULL
)
SELECT regexp_substr(text,'\#[a-z0-9_]+',1,level,'i') as tag
FROM texttab
CONNECT BY regexp_substr(text,'\#[a-z0-9_]+',1,level,'i') IS NOT NULL


This query returns all the keyword prefixed with # from ROOT_CAUSE column in my cust_bug_data table.
currently output is like as follows:
#test
#timing
#test
#timing
#code


I want # to be removed from the output.

So I am looking my output to be like:
test
timing
test
timing
code 


Please advice me on how to do this.

and Chris said...

Any reason you can't use:

replace(text, '#')


?

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 21, 2017 - 4:08 pm UTC

Following query worked for me.

select replace(tag,'#','') as tag, from(
with texttab as
(
SELECT
ROOT_CAUSE as text
from cust_bug_data where ROOT_CAUSE is not NULL
)
SELECT regexp_substr(text,'\#[a-z0-9_]+',1,level,'i') as tag
FROM texttab
CONNECT BY regexp_substr(text,'\#[a-z0-9_]+',1,level,'i') IS NOT NULL) t
Chris Saxon
September 21, 2017 - 4:13 pm UTC

Glad you got this working.

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.