Thanks for the question, Subhash.
Asked: September 21, 2017 - 4:54 pm UTC
Last updated: September 25, 2017 - 3:42 am UTC
Version: 12.1
Viewed 1000+ times
You Asked
Hi,
I have a cust_bug_test table with 2 columns(ROOT_CAUSE, BUG_NUMBER) like as follows:
create table cust_bug_test(ROOT_CAUSE VARCHAR(250), BUG_NUMBER NUMBER NOT NULL PRIMARY KEY)
insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #test issue.', 25940149)
insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #timing issue', 25768241)
insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('#timing', 26167402)
insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('this is #test issue.', 23250474)
insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #code issue', 23742921)
Now my requirement is to extract the hashtag word(without #) from fist column and corresponding BUG_NUMBER column from second column.
For example my query should return 2 columns like as follows:
TAG BUG_NUMBER
----- --------
test 25940149
timing 25768241
timing 26167402
test 23250474
code 23742921
Please let me know the query for above result.
I am trying to write the query for above result, but I could get only the first column after filtering #, and not able to get the corresponding BUG_NUMBER.
select replace(tag,'#','') as tag from(
with texttab as
(
SELECT
ROOT_CAUSE as text
from cust_bug_test 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
My above query results only 1 column.:
TAG
----
test
timing
timing
test
code
Thanks,
Subhash
and Connor said...
Something like this ?
SQL> @drop cust_bug_test
Y1 Y2
----------------------- -------------------------
TABLE cascade constraints purge
1 row selected.
Table dropped.
SQL> create table cust_bug_test(ROOT_CAUSE VARCHAR(250), BUG_NUMBER NUMBER NOT NULL PRIMARY KEY);
Table created.
SQL> insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #test issue.', 25940149);
1 row created.
SQL> insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #timing issue', 25768241);
1 row created.
SQL> insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('#timing', 26167402);
1 row created.
SQL> insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('this is #test issue.', 23250474);
1 row created.
SQL> insert into cust_bug_test(ROOT_CAUSE, BUG_NUMBER ) values('This is a #code issue', 23742921);
1 row created.
SQL>
SQL> select regexp_substr(root_cause,'\#[a-z0-9_]+',1,1,'i') hashtag, bug_number
2 from cust_bug_test;
HASHTAG BUG_NUMBER
------------------------------ ----------
#test 25940149
#timing 25768241
#timing 26167402
#test 23250474
#code 23742921
5 rows selected.
SQL>
SQL> select regexp_substr(root_cause,'\#([a-z0-9_]+)',1,1,'i',1) hashtag, bug_number
2 from cust_bug_test;
HASHTAG BUG_NUMBER
------------------------------ ----------
test 25940149
timing 25768241
timing 26167402
test 23250474
code 23742921
5 rows selected.
SQL>
Rating
(3 ratings)
Is this answer out of date? If it is, please let us know via a Comment