Question : Wildcard for string search

I have a stored procedure which accepts the string parameter for address filtering and this is how it is used in the stored procedure: I have a logic to process this parameter

if p_addr is null or p_addr=''
V_addr = '%1%2%0%0%B%R%O%A%D%' --( basically if the user want to search the string she will enter 1200 BROAD from crystal report)
else v_addr = p_addr;
..
..

--SQL where this filter is used:

select * from
tab a
where rtrim(ltrim(address))= v_addr
...
..

Now my question is if the user enters any address string as parameter (say 1100 Lincoln st) I want my V_addr to have wild card '%' inserted between each character of the search string entered by user. In this case my v_addr should be
%1%1%0%0%L%I%N%C%O%L%N%%S%T%. How do I do this in plsql..

Please let me know..

Thanks

Answer : Wildcard for string search

in 10g or higher

select '%' || UPPER(REGEXP_REPLACE(REPLACE('1100 Lincoln st', ' '), '(.)', '\1%')) from dual

Random Solutions  
 
programming4us programming4us