1

If an input string is in the format String#String or String#String;String#String where String can have any number of Capital letter alphabets, underscore,then it should return Y else it should return N.

How can it be done using Regex in PL/SQL only in single SQL query?
(P.S. not using PL/SQL procedures/function.)

Example:- If input string is "CASISA#Y" or "INVOPT#LUMREG;LUMSUM#2000;REGSUM#8000", a 'Y' should be returned else an 'N' should be returned. Note - Please do not build a PL/SQL procedure to accomplish this instead it should be just a SQL that makes use of oracle Regular expression functions.*

3
  • Could you clarify your question a little bit? Provide an example string and indicate the substrings you are trying to match. What have you tried already? Commented Jan 22, 2013 at 17:39
  • plsql check question again i have added example Commented Jan 22, 2013 at 17:49
  • What is the version of Oracle? Commented Jan 22, 2013 at 17:51

1 Answer 1

2

You can use regexp_like regular expression function to achieve desired result:

with t1(col) as(
  select 'CASISA#Y'                              from dual union all
  select 'INVOPT#LUMREG;LUMSUM#2000;REGSUM#8000' from dual union all
  select 'CASISA#Y;'                             from dual union all -- extra data
  select 'INVOPT#LUMREG;LUMSUM#2000;#8000'       from dual           -- extra data
)
select col
     , case
         when regexp_like(col, '^(\w+#\w+;)*(\w+#\w+){1}$')
         then 'Y'
         else 'N'
       end  as "Y/N"
  from t1 

Result:

COL                                        Y/N
--------------------------------------------------
CASISA#Y                                    Y
INVOPT#LUMREG;LUMSUM#2000;REGSUM#8000       Y
CASISA#Y;                                   N
INVOPT#LUMREG;LUMSUM#2000;#8000             N

SQLFiddle example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.