Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern Match in Oracle

Status
Not open for further replies.

jamesgao

MIS
May 11, 2001
1
US
Hi All,

I need to write a function to convert a varchar2 value from a pattern of two alpha charatcer followed by two numeric character, then followed by a alpha character, then anthing after that to a three numeric charater after the first two characters. Such as "ab99c91" to "ab099c19". Please help.

Thanks,

--James
 
This should work 'til you find something more efficient:

Code:
UPDATE my_tbl
SET    my_col = substr(my_col,1,2)||'0'||substr(my_col,3)
WHERE  length(my_col) = 7
  AND  substr(my_col,1,1) NOT between '0' and '9'
  AND  substr(my_col,2,1) NOT between '0' and '9'
  AND  substr(my_col,3,1)     between '0' and '9'
  AND  substr(my_col,4,1)     between '0' and '9'
  AND  substr(my_col,5,1) NOT between '0' and '9'
  AND  substr(my_col,6,1)     between '0' and '9'
  AND  substr(my_col,7,1)     between '0' and '9'
 
substr(field,1,2)||'0'||substr(field,3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top