Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 mySQL: url_decode that respects utf8 characters. Jump to:  
Category: >> mySQL >> url_decode that respects utf8 characters. Bookmark and Share

<< lastnext >>

Snippet Name: url_decode that respects utf8 characters.

Description: Does url_decoding while respecting utf8 characters.

Comment: (none)

Language: PL/SQL
Highlight Mode: MYSQL
Last Modified: March 02nd, 2009

DELIMITER $$
 
DROP FUNCTION IF EXISTS `url_decode` $$
CREATE DEFINER=`root`@`%` FUNCTION `url_decode`(original_text TEXT) RETURNS TEXT CHARSET utf8
BEGIN
     DECLARE new_text TEXT DEFAULT NULL;
     DECLARE pointer INT DEFAULT 1;
     DECLARE end_pointer INT DEFAULT 1;
     DECLARE encoded_text TEXT DEFAULT NULL;
     DECLARE result_text TEXT DEFAULT NULL;
 
     SET new_text = REPLACE(original_text,'+',' ');
 
     SET pointer = LOCATE("%", new_text);
     while pointer <> 0 && pointer < (CHAR_LENGTH(new_text) - 2) DO
          SET end_pointer = pointer + 3;
          while MID(new_text, end_pointer, 1) = "%" DO
               SET end_pointer = end_pointer+3;
          END while;
 
          SET encoded_text = MID(new_text, pointer, end_pointer - pointer);
          SET result_text = CONVERT(UNHEX(REPLACE(encoded_text, "%", "")) USING utf8);
          SET new_text = REPLACE(new_text, encoded_text, result_text);
          SET pointer = LOCATE("%", new_text, pointer + CHAR_LENGTH(result_text));
     END while;
 
     return new_text;
 
END $$
 
DELIMITER ;


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 187 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?