i have a column category which has the following data:
0100 Single Function Inkjet Printers
0100 Wireless Phones
400 optics (421)
4000 sound and recording (267)
80000 electrical & heating (60)
81000 plumbing
Accessories
Action Figures/Collectibles
I am trying to create a category calculated field in SQL which will have only the text:
Single Function Inkjet Printers
Wireless Phones
optics
sound and recording
electrical & heating
plumbing
Accessories
Action Figures/Collectibles
I have tried using a combination of left, right, trim and substring functions to do so, but havent been successfull. Any help would be appreciated.
2
Answers
If you’re using MySQL 8.0 or higher this can be done using regex_replace:
This example replaces numbers with optional round brackets, if you have any other number formats that needs to be replaced – see the regex manual.
Demo:
https://dbfiddle.uk/d8Aapd5j
fiddle
TRIM()
provides leading space removing when the substring to be deleted is a prefix.