Home » SQL & PL/SQL » SQL & PL/SQL » how to match multiple wildcards via metadata table
how to match multiple wildcards via metadata table [message #650699] Fri, 29 April 2016 15:55 Go to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
I want a user to be able to enter patterns into a table via a form that I will use in a query to find all matching rows in a table, but I have only done this via hardcoding in a regexp_like condition, such as:

create table test_multi (
col1 varchar2(20),col2 number(11));

insert into test_multi values ('GARY',10);
insert into test_multi values ('FRED',20);
insert into test_multi values ('NED',30);
insert into test_multi values ('JOHNNIE',40);
insert into test_multi values ('JILL',500);

select * from test_multi
where regexp_like(COL1,'^(JI|G)');

COL1                             COL2
-------------------- ----------------
GARY                               10
JILL                              500


What if I wanted the user to be able to change the matching condition whenever they wanted and now wants to use this? I don't know why I never needed this before and now I just cannot think of a way to do it.

select * from test_multi
where regexp_like(COL1,'(ED)$');

COL1                             COL2
-------------------- ----------------
FRED                               20
NED                                30


Can I store the patterns in a table and somehow utilize the table in the condition?

Colunn could contain value ^(JI|G) or (ED)$ or any other regular expression??


Re: how to match multiple wildcards via metadata table [message #650700 is a reply to message #650699] Fri, 29 April 2016 18:05 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
I am not real clear on what you want to do or why. Is the following what you want? If not, then please explain further.

SCOTT@orcl> select * from test_multi
  2  /

COL1                       COL2
-------------------- ----------
GARY                         10
FRED                         20
NED                          30
JOHNNIE                      40
JILL                        500

5 rows selected.

SCOTT@orcl> select * from test_metadata
  2  /

REG_EXP_COND
------------------------------
^(JI|G)
(ED)$

2 rows selected.

SCOTT@orcl> select t2.reg_exp_cond, t1.col1, t1.col2
  2  from   test_multi t1, test_metadata t2
  3  where  regexp_like (t1.col1, t2.reg_exp_cond)
  4  order  by t2.reg_exp_cond
  5  /

REG_EXP_COND                   COL1                       COL2
------------------------------ -------------------- ----------
(ED)$                          FRED                         20
(ED)$                          NED                          30
^(JI|G)                        GARY                         10
^(JI|G)                        JILL                        500

4 rows selected.

Re: how to match multiple wildcards via metadata table [message #650732 is a reply to message #650700] Mon, 02 May 2016 08:13 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Nope Barbara, you got me, even though my explanation left a bit to be desired. It was 5 minutes before the end of the day on Friday, at the end of a long week, so my question was a little disjointed.

All I wanted was for a user definable list of regular expressions to be stored in a table. I should not even have mentioned a form as it was irrelevant to the question.
Re: how to match multiple wildcards via metadata table [message #650737 is a reply to message #650732] Mon, 02 May 2016 09:42 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
And she showed you what you asked for. The regular expressions are in the table test_metadata and her test data is in test_multi.
Re: how to match multiple wildcards via metadata table [message #650744 is a reply to message #650737] Mon, 02 May 2016 15:36 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Ugh, can I use the excuse that I was less than 15 minutes into my week and still in weekend mode, because my wacky grasp of grammar made my response sound like Barbara's answer was not what I was looking for.

However, her answer was exactly what I was looking for.

Sorry, I have been away from here for a loooooong time. I forgot how to make unambiguous, non-obscure postings. I need practice. Normally, I only answer questions, not ask them (I think I maybe asked 3 questions), so I am very inept at conveying my gratitude.
Re: how to match multiple wildcards via metadata table [message #650745 is a reply to message #650744] Mon, 02 May 2016 16:15 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
It's O.K. I got that I got you. Hopefully Bill gets it now. Perhaps it's time for a caffeinated beverage.

Previous Topic: call a web service in a function in plsql
Next Topic: Unable to get values from associative arrays into a different procedure
Goto Forum:
  


Current Time: Thu Apr 25 18:39:46 CDT 2024