MYSQL convert windows1251 into UTF-8 enconding procedure

Dec 17, 2008 Author: MYSQL Expert

MYSQL convert windows1251 into UTF-8 enconding procedure

CREATE FUNCTION STR_1251_UTF8(@s varchar(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
    declare
@c209 char(1), @c208 char(1), @c129 char(1), @i int, @c int, @t varchar(8000)
   
SET @c209 = char(209)
   
SET @c208 = char(208)
   
SET @c129 = char(129)
   
SET @i=1
   
SET @t = ''
   
WHILE @i=192 and @c<=239) SET @t=@t+@c208+char(@c-48)
              
else
       
if (@c>239) SET @t=@t+@c209+char(@c-112)
               
else
        
if (@c=184) SET @t=@c209+@c209
                
else
          
if (@c=168) SET @t=@c208+@c129
                  
else SET @t=@t+SUBSTRING(@s,@i,1)
       
SET @i=@i+1          
   
END

    RETURN
@t
END

 


views 6330
  1. Add New Comment