Home >Database >Mysql Tutorial >MySQL JOIN操作报错问题小解

MySQL JOIN操作报错问题小解

WBOY
WBOYOriginal
2016-06-07 15:01:231359browse

上面的调整基本上能解决大部分此类问题,但是我们的存储过程依然执行不了。经过一番分析,发现我们的存储过程中会新建一个临时表,代码大概是这样: INSERT INTO tmp(region, cell, relation)SELECT DISTINCT r.region, t.cell, -1FROM rr_tmp r LEFT JOIN (

上面的调整基本上能解决大部分此类问题,但是我们的存储过程依然执行不了。经过一番分析,发现我们的存储过程中会新建一个临时表,代码大概是这样:

INSERT INTO tmp(region, cell, relation)
SELECT DISTINCT r.region, t.cell, -1
FROM rr_tmp r LEFT JOIN ( SELECT DISTINCT region, cell FROM ri_tmp ri, ce_tmp ct WHERE ri.region=ce.region) t
ON r.region=t.region WHERE r.region is null;

我们怀疑字符编码不一致的原因是这个临时表的字符编码与rr_tmp表的字符编码不一致导致的,但是如何控制临时表的字符编码呢?

临时表的字符编码其实就是数据库的默认字符编码,通过 show create database test_db 可以看到数据库的字符编码 将数据库的字符编码修改成与rr_tmp的字符编码一致,就OK了 

alter database test_db characeter set utf8

 

Date: 2015-02-04T15:58+0800

Author: CobbLiu

Org version 7.9.3f with Emacs version 24

Statement:
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