I have a MySQL table with addresses and some have 5 digit zip codes and some have 9 digit zip codes. A sample record would be like this
940 Huguenot Ave Staten Island, NY 10312-4313
I need to standardize the database and make all records 5 digit zip codes. My sudo code for something like this was like this
If regex [0](5 numeric digits )-[1](4 numeric digits) then update table replace('-[1]','');
Any help would be appreciated!
Thanks,
UPDATE —
zipcode is not an independent field, it is part of the address column, (a sample is above)
Success!
I ended up using a combination of REGEX and SUBSTR using the length of the field -5. Thanks, guys!
MySQL doesn’t support regex replace operations. However, you could first find those records that contain a 9-digit ZIP code:
and then delete the five characters following the dash.