Created
February 10, 2018 19:00
-
-
Save cybersholt/fcbca959c0049e26c354527dbfc4897f to your computer and use it in GitHub Desktop.
A MySQL routine to extract query strings from a given column, usage fn_getparam('PARAM',COLUMN)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE FUNCTION `fn_getparam`(param varchar(55), url varchar(2048)) RETURNS varchar(2048) CHARSET latin1 COLLATE latin1_general_cs | |
BEGIN | |
declare val varchar(2048); | |
declare _param varchar(60) DEFAULT CONCAT(param,'='); | |
select | |
case | |
when locate(concat('&',_param), url) > 0 | |
then right(url, length(url) - (locate(concat('&',_param),url)+length(concat('&',_param))-1)) | |
when locate(concat('?',_param), url) > 0 | |
then right(url, length(url) - (locate(concat('?',_param),url)+length(concat('?',_param))-1)) | |
when locate(concat('#',_param), url) > 0 | |
then right(url, length(url) - (locate(concat('#',_param),url)+length(concat('#',_param))-1)) | |
when locate(_param,url) > 0 | |
then right(url, length(url) - (locate(_param,url)+length(_param)-1) ) | |
else null | |
end | |
into val; | |
set val = replace(replace(left(val, locate('&',concat(val,'&'))-1),'%20',' '),'+',' '); | |
RETURN val; | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://www.garrettpatterson.com/2013/02/14/mysql-function-to-get-querystring-parameter-of-url/