Home > Database > Mysql Tutorial > body text

How to Convert `varbinary` to Character Data in MySQL?

Susan Sarandon
Release: 2024-10-27 04:22:30
Original
984 people have browsed it

How to Convert `varbinary` to Character Data in MySQL?

Converting varbinary to Character Data in MySQL

Are you struggling to convert data in a varbinary field to a character-based format (char/varchar) in MySQL? Here's how you can accomplish this in MySQL version 5.10:

Conversion Methods

To convert varbinary to char/varchar, you can utilize the CAST or CONVERT functions:

<code class="sql">CAST(foo AS CHAR(100))
CONVERT(foo, CHAR(100))</code>
Copy after login

Replace "foo" with the name of your varbinary field and "CHAR(100)" with the desired character data type and length.

Supported Data Types

MySQL supports casting varbinary to the following data types:

  • BINARY[(N)]
  • CHAR[(N)]
  • DATE
  • DATETIME
  • DECIMAL[(M[,D])]
  • SIGNED [INTEGER]
  • TIME
  • UNSIGNED [INTEGER]

Limitations

Note that you cannot directly cast varbinary to varchar. This is due to an unresolved MySQL bug from 2008.

Example Usage

To convert the contents of the "data" field from varbinary to CHAR with a maximum length of 100 characters, use the following query:

<code class="sql">UPDATE my_table SET data = CAST(data AS CHAR(100));</code>
Copy after login

The above is the detailed content of How to Convert `varbinary` to Character Data in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!