gpt4 book ai didi

MySQL castr 运算符

转载 作者:行者123 更新时间:2023-11-29 03:37:44 24 4
gpt4 key购买 nike

下面的查询是否有任何更短的等价物:(我不能改变表)。转换运算符在这里适用吗?

select convert(old_text using utf8) as text,
convert(rev_timestamp using utf8) as ts,
convert(rev_user_text using utf8) as user from revision;

更新:表架构是:

CREATE TABLE `revision` (
`rev_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`rev_page` INT(10) UNSIGNED NOT NULL,
`rev_text_id` INT(10) UNSIGNED NOT NULL,
`rev_comment` TINYBLOB NOT NULL,
`rev_user` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`rev_user_text` VARCHAR(255) NOT NULL DEFAULT '' COLLATE 'latin1_bin',
`rev_timestamp` BINARY(14) NOT NULL DEFAULT '\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0',
`old_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`old_text` MEDIUMBLOB NOT NULL,
`old_flags` TINYBLOB NOT NULL,
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB

最佳答案

最好是改变你的表并为你需要的列设置 utf8 而不是每次都转换它们

    ALTER TABLE t MODIFY old_text CHAR(50) CHARACTER SET utf8;
ALTER TABLE t MODIFY rev_timestamp CHAR(50) CHARACTER SET utf8;
ALTER TABLE t MODIFY rev_user_text CHAR(50) CHARACTER SET utf8;

然后正常选择它们。

select old_text  as text, rev_timestamp  as ts, rev_user_text as user 
from revision;

注意:关于char(50)根据自己的需要更改。

关于MySQL castr 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18958280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com