How do I convert from BLOB to TEXT in Mysql?

After some googling for you i've found this. It's an answer to a person who wants to convert blob to char(1000) with utf8 encoding

CAST(a.ar_options AS CHAR(10000) CHARACTER SET utf8)

This is his answer. There is probably much more you can read about CAST right here. Hope it helps some.




Thats unnecessary, just use SELECT CONVERT(column USING utf8) FROM..... instead of justSELECT column FROM.....

share|improve this answer
 
1  
This doesn't work for me. – chaostheory Jun 21 '11 at 21:06
4  
Usage: SELECT CONVERT(column USING utf8) FROM table; – bmaupin Oct 2 '12 at 19:32
 
This works great for those GROUP_CONCATs that convert your output to blobs and you really want them as strings. I had an issue similar to the OP's while using Node.JS with the node-mysql library - this fixed all group_concat issues. – marksyzm Jul 26 at 13:53

or you can use this function

DELIMITER $$

CREATE FUNCTION BLOB2TXT (blobfield VARCHAR(255)) RETURNS longtext
DETERMINISTIC
NO SQL
BEGIN
       RETURN CAST(blobfield AS CHAR(10000) CHARACTER SET utf8); 
END
$$


DELIMITER ;
share|improve this answer



select * from test_table where Test_data = CAST( blobObject AS CHAR );

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章