如何在 MySQL 中将 BLOB 转换为 VARCHAR?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8627621/
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 22:09:01  来源:igfitidea点击:

How do I convert BLOB into VARCHAR in MySQL?

mysqlblobvarchar

提问by ilhan

It is in a shared host and I access with Navicat. I have field with BLOB and I want to convert it into VARCHAR. I've tried in the design screen but everything was lost. I backed up.

它位于共享主机中,我使用 Navicat 访问。我有 BLOB 字段,我想将其转换为 VARCHAR。我已经在设计屏幕中尝试过,但一切都丢失了。我备份了。

回答by Luis Nuesi Tejada

try using this, I found it some time ago, you can convert it to char, not to Varchar2or Varchar, haven't test it yet. Try:

尝试使用这个,我前段时间发现的,你可以将其转换为char,而不是Varchar2Varchar,尚未测试。尝试:

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

MySQL treat data unique. Hence there is a difference between Blob and Text. Text simply means a text string stored as original, not in binary, whereas a blob is a text string stored as a binary.

MySQL 对待数据是唯一的。因此,Blob 和 Text 之间存在差异。文本只是意味着存储为原始文本的文本字符串,而不是二进制的,而 blob 是存储为二进制的文本字符串。

回答by ilhan

try with the below query

尝试使用以下查询

alter table table_name change field_name field_name VARCHAR(1000);

回答by Jeff Potter

I found this of MySQL's Website if you are trying to change your column to a different data type and keep the new data type in the database. Works great for what I need!

如果您尝试将列更改为不同的数据类型并在数据库中保留新的数据类型,我会在 MySQL 的网站上找到这个。非常适合我的需要!

ALTER TABLE table_name CHANGE col col1 varchar(100)