[英]MySQL Set collate by a variable
為了避免在不同系統上更新數據庫時出現“非法勾結”現象,我想這樣做:
SELECT @collcation := TABLE_COLLATION FROM information_schema.tables WHERE table_schema = "information_schema" AND TABLE_NAME = "COLUMNS";
SELECT * FROM ... WHERE COLUMN_NAME="extended" COLLATE @collcation;
是否可以通過變量設置COLLATE?
這是我的例子:
select @collcation := TABLE_COLLATION
from information_schema.tables
where table_schema='testdrive_unit_test' and TABLE_NAME = "car"
;
+--------------------------------+
| @collcation := TABLE_COLLATION |
+--------------------------------+
| latin1_swedish_ci |
+--------------------------------+
select * from car order by model collate @collcation
;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@collcation' at line 1
select * from car order by model collate latin1_swedish_ci limit 3
;
+----+----------+-------+----------+
| id | brand_id | model | maxSpeed |
+----+----------+-------+----------+
| 14 | 5 | 301 | 160 |
| 15 | 5 | 401 | 190 |
| 16 | 5 | 407 | 210 |
+----+----------+-------+----------+
3 rows in set (0.00 sec)
根據這種觀點,我認為不可能通過變量設置整理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.