Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

REGEXP_REPLACE in ORACLE [on hold]

$
0
0

I have an input string with numerous formats. It might be:

NCA385Useless Text
NCA 386:Useless Text
NC345/545Some Useless Text
NCA400/500 Some Useless Text
NC 300/500Some Useless Text
NC  450/550(Some Uselss Text)
NCA 200 Useless Text
NCA 220/520:Useless Text
NC250 (Some Useless Text)
NC 300 (Some Useless Text)

I want to use this field in an ORACLE CASE STATEMENT WITHIN A VIEW (i.e. CREATE OR REPLACE VIEW…) like this:

case
   when (course_no like '%') then
      REGEXP_REPLACE ???
   end course_id

I know enough about regular expressions to handle some of this, yet there are so many patterns to that data, that guessing all of them is just impossible. The hoped for outcome of “course_id” from the input data above will be:

NCA385
NCA386
NC345/545
NCA400/500
NC300/500
NC450/550
NCA200
NCA220/520
NC250
NC300

The input variable will always be (from the front of the variable) ^[A-Z]{2,4}. After that, there might (or might not) be one or two spaces followed by 3 digits, followed (perhaps) by a forward slash and three more digits. If there is no forward slash, the rest of the input variable is useless and need not be returned. If there is a forward slash, return the slash and the three following digits. Eliminate any space between the last of the beginning alphas and the first encountered digit. It just seems that at some point you could use the pipe | as a logical OR to expand the pattern match. Any help you can provide me will be greatly appreciated.


Viewing all articles
Browse latest Browse all 717

Trending Articles