Cracking of garbled characters in MySQL stored procedures

Source: Internet
Author: User

The following articles mainly introduce the actual solution of garbled characters in the MySQL stored procedure. We all know that if there is a problem with the stored procedure, it is generally manifested that data cannot be correctly queried. The following describes the specific content of the article. I hope you will gain some benefits.

Both the data table and field are the Chinese content stored in utf8. After connecting to the database, set names utf8; is also used to SET the encoding. However, Chinese fields cannot be queried during the MySQL stored procedure. For some logic reasons, the stored procedure uses a cursor and defines some local variables.

 
 
  1. CREATE PROCEDURE `PROC_FOOBAR`(id INTEGER)  
  2. BEGIN  
  3. DECLARE user_id VARCHAR(32) ;  

Code omitted

 
 
  1. END 

User_id participates in a query in the code

 
 
  1. SELECT * FROM `table1` WHERE `UID` = user_id 

In the stored procedure, the user_id is output and the English content is normal, but the Chinese content is garbled.

At first, I thought there was a problem with the encoding of the MySQL stored procedure, but the content without variables was normal. I checked it online and someone encountered the same problem:

Http: // 203.208.37.132/search? Q = cache: VUrY1gSBQGoJ: Enabled

But obviously, you only need to set the encoding correctly.

Suddenly, I ignored NND and character set. The solution is as follows:

 
 
  1. CREATE PROCEDURE `PROC_FOOBAR`(id INTEGER)  
  2. BEGIN  
  3. DECLARE code, user_id VARCHAR(32) CHARACTER SET utf8;  

Code omitted

 
 
  1. END  

The above content is an introduction to the solution to the garbled MySQL stored procedure. I hope you will find some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.