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.
- CREATE PROCEDURE `PROC_FOOBAR`(id INTEGER)
- BEGIN
- DECLARE user_id VARCHAR(32) ;
Code omitted
- END
User_id participates in a query in the code
- 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:
- CREATE PROCEDURE `PROC_FOOBAR`(id INTEGER)
- BEGIN
- DECLARE code, user_id VARCHAR(32) CHARACTER SET utf8;
Code omitted
- END
The above content is an introduction to the solution to the garbled MySQL stored procedure. I hope you will find some gains.