MySQL 将BLOB转换为sql中的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14869572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:34:39  来源:igfitidea点击:

convert BLOB to text in sql

mysqlsqlsql-serverblob

提问by shockwave

I have a field in my database table with data type as BLOB.How can I view the content as text/stringusing a SELECTquery in SQL. the content's MIMETYPEis 'text/xml charset=UTF8'

我的数据库表中有一个字段,其数据类型为BLOB.How 可以text/string使用.How 中的SELECT查询查看内容SQL。内容MIMETYPE'text/xml charset=UTF8'

I tried with this, I'm not sure if im right with the syntax

我试过这个,我不确定我的语法是否正确

SELECT 
CAST((SELECT column FROM myTable WHERE ID='56')AS CHAR(10000) CHARACTER SET utf8)

and also

并且

SELECT 
CONVERT(VARCHAR(max), CAST((SELECT column FROM myTable WHERE ID='56') 
as binary)) from BIZDOCCONTENT

many Thanks

非常感谢

回答by urbanspr1nter

Try:

尝试:

SELECT CONVERT(object USING utf8)
FROM tablename

回答by Devart

Try this query -

试试这个查询 -

SELECT CONVERT(column USING utf8) FROM myTable WHERE ID=56

回答by zerra

I had the same problem - I just changed the field type in phpmyadmin! And what i see :

我遇到了同样的问题 - 我只是在 phpmyadmin 中更改了字段类型!我所看到的:

ALTER TABLE pagesCHANGE contentcontentTEXT NULL DEFAULT NULL
('content' - my field which was in BLOB-type)

ALTER TABLE pagesCHANGE contentcontentTEXT NULL DEFAULT NULL
('content' - 我的字段是 BLOB 类型)

回答by imratE

CREATE OR REPLACE FUNCTION HASTANE.getXXXXX(p_rowid in rowid) RETURN VARCHAR2
AS
    l_data long;
BEGIN
    SELECT XXXXXX INTO l_data FROM XXXXX WHERE rowid = p_rowid;
    RETURN substr(l_data, 1, 4000);
END getXXXXXX;

回答by Ankit Agrawal

Set your content type in php:

在 php 中设置您的内容类型:

header("Content-type: image/jpg"); //Send the content Type here.
print $data['blob_data'];