MySQL Forums
Forum List  »  Stored Procedures

Create Function to replace quotes as inches
Posted by: Rob Oley
Date: March 30, 2021 02:54PM

I want to create a function that will replace the quotation symbols with the word in. Example replace('3" Screw', '"', 'in') however I also have to take into account replace('Label "Stop"', '"', ''). So I was able to build an SQL Function for this but I can't find out how to build the MYSQL function. The SQL Function is what follows. How do I translate this to MYSQL?


CREATE function [dbo].[TRE_replace_string](@string varchar(100))
returns varchar(100)
as
BEGin

select @string=REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(@string,'1"','1in'),'2"','2in'),'3"','3in'),'4"','4in'),'5"','5in'),'6"','6in'),'7"','7in'),'8"','8in'),'9"','9in'),'0"','0in')
select @string=REPLaCE(REPLaCE(@string,'"A','A'),'A"','A')
select @string=REPLaCE(REPLaCE(@string,'"B','B'),'B"','B')
select @string=REPLaCE(REPLaCE(@string,'"C','C'),'C"','C')
select @string=REPLaCE(REPLaCE(@string,'"D','D'),'D"','D')
select @string=REPLaCE(REPLaCE(@string,'"E','E'),'E"','E')
select @string=REPLaCE(REPLaCE(@string,'"F','F'),'F"','F')
select @string=REPLaCE(REPLaCE(@string,'"G','G'),'G"','G')
select @string=REPLaCE(REPLaCE(@string,'"H','H'),'H"','H')
select @string=REPLaCE(REPLaCE(@string,'"I','I'),'I"','I')
select @string=REPLaCE(REPLaCE(@string,'"J','J'),'J"','J')
select @string=REPLaCE(REPLaCE(@string,'"K','K'),'K"','K')
select @string=REPLaCE(REPLaCE(@string,'"L','L'),'L"','L')
select @string=REPLaCE(REPLaCE(@string,'"M','M'),'M"','M')
select @string=REPLaCE(REPLaCE(@string,'"N','N'),'N"','N')
select @string=REPLaCE(REPLaCE(@string,'"O','O'),'O"','O')
select @string=REPLaCE(REPLaCE(@string,'"P','P'),'P"','P')
select @string=REPLaCE(REPLaCE(@string,'"Q','Q'),'Q"','Q')
select @string=REPLaCE(REPLaCE(@string,'"R','R'),'R"','R')
select @string=REPLaCE(REPLaCE(@string,'"S','S'),'S"','S')
select @string=REPLaCE(REPLaCE(@string,'"T','T'),'T"','T')
select @string=REPLaCE(REPLaCE(@string,'"U','U'),'U"','U')
select @string=REPLaCE(REPLaCE(@string,'"V','V'),'V"','V')
select @string=REPLaCE(REPLaCE(@string,'"W','W'),'W"','W')
select @string=REPLaCE(REPLaCE(@string,'"X','X'),'X"','X')
select @string=REPLaCE(REPLaCE(@string,'"Y','Y'),'Y"','Y')
select @string=REPLaCE(REPLaCE(@string,'"Z','Z'),'Z"','Z')
select @string=REPLaCE(REPLaCE(@string,'"(','('),')"',')')

select @string=REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(REPLaCE(@string,'1''','1ft'),'2''','2ft'),'3''','3ft'),'4''','4ft'),'5''','5ft'),'6''','6ft'),'7''','7ft'),'8''','8ft'),'9''','9ft'),'0''','0ft')
select @string=REPLaCE(REPLaCE(@string,'''A','A'),'A''','A')
select @string=REPLaCE(REPLaCE(@string,'''B','B'),'B''','B')
select @string=REPLaCE(REPLaCE(@string,'''C','C'),'C''','C')
select @string=REPLaCE(REPLaCE(@string,'''D','D'),'D''','D')
select @string=REPLaCE(REPLaCE(@string,'''E','E'),'E''','E')
select @string=REPLaCE(REPLaCE(@string,'''F','F'),'F''','F')
select @string=REPLaCE(REPLaCE(@string,'''G','G'),'G''','G')
select @string=REPLaCE(REPLaCE(@string,'''H','H'),'H''','H')
select @string=REPLaCE(REPLaCE(@string,'''I','I'),'I''','I')
select @string=REPLaCE(REPLaCE(@string,'''J','J'),'J''','J')
select @string=REPLaCE(REPLaCE(@string,'''K','K'),'K''','K')
select @string=REPLaCE(REPLaCE(@string,'''L','L'),'L''','L')
select @string=REPLaCE(REPLaCE(@string,'''M','M'),'M''','M')
select @string=REPLaCE(REPLaCE(@string,'''N','N'),'N''','N')
select @string=REPLaCE(REPLaCE(@string,'''O','O'),'O''','O')
select @string=REPLaCE(REPLaCE(@string,'''P','P'),'P''','P')
select @string=REPLaCE(REPLaCE(@string,'''Q','Q'),'Q''','Q')
select @string=REPLaCE(REPLaCE(@string,'''R','R'),'R''','R')
select @string=REPLaCE(REPLaCE(@string,'''S','S'),'S''','S')
select @string=REPLaCE(REPLaCE(@string,'''T','T'),'T''','T')
select @string=REPLaCE(REPLaCE(@string,'''U','U'),'U''','U')
select @string=REPLaCE(REPLaCE(@string,'''V','V'),'V''','V')
select @string=REPLaCE(REPLaCE(@string,'''W','W'),'W''','W')
select @string=REPLaCE(REPLaCE(@string,'''X','X'),'X''','X')
select @string=REPLaCE(REPLaCE(@string,'''Y','Y'),'Y''','Y')
select @string=REPLaCE(REPLaCE(@string,'''Z','Z'),'Z''','Z')
select @string=REPLaCE(REPLaCE(@string,'''(','('),')''',')')


RETURN @string

END
GO

Options: ReplyQuote


Subject
Views
Written By
Posted
Create Function to replace quotes as inches
1212
March 30, 2021 02:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.