???MySQL???????URL????????(urldecode),????MySQL?????UNHEX
?CONVERT
????
???????????:
- ??????????????URL?????:
DELIMITER $$ CREATE FUNCTION urldecode(input VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC BEGIN DECLARE output VARCHAR(255) DEFAULT ''; DECLARE temp VARCHAR(2) DEFAULT ''; DECLARE i INT DEFAULT 1; WHILE i <= LENGTH(input) DO IF SUBSTRING(input, i, 1) = '%' THEN SET temp = CONCAT(SUBSTRING(input, i+1, 1), SUBSTRING(input, i+2, 1)); SET output = CONCAT(output, CHAR(CONVERT(UNHEX(temp), UNSIGNED INTEGER))); SET i = i + 3; ELSE SET output = CONCAT(output, SUBSTRING(input, i, 1)); SET i = i + 1; END IF; END WHILE; RETURN output; END$$ DELIMITER ;
- ????????????URL?????:
SELECT urldecode('https://www.google.com/') AS decoded_url;
????????URL:https://www.google.com/
??????????,???????MySQL??????URL?????,?????????