简体   繁体   中英

mysql select concat(charfield, format(doublefield,8)) gives error 1267

which is ironic on two counts, 1) because concat(charfield, doublefield) works (it doesn't mind when one of the fields to be concatenated is numeric) and 2) because the mysql reference shows this: CONCAT(str1,str2,...) as the prototype for CONCAT and for FORMAT this: "FORMAT(X,D) Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string ".

In desperation I tried select concat(symbol, cast(format(closeprice,8) as char)) , which worked. So you could be thinking, "why is this guy wasting our time, he found something that works", which is true. But it doesn't make sense to me, and so I was wondering if anyone could clear it up?

1267 is illegal mix of collations. The collation (alphabetical sorting) of charfield and the collation of the string returned from FORMAT (probably your db server's default collation) are different.

Modify either the column's collation or the server default collation, or do the cast.

I had the same issue today and this is what worked for me:

Portion of query:

CONCAT(payment_currency," ", CONVERT(FORMAT(payment_amount, 2) using utf8)) AS payment_gross_amount

Result:

PHP 1,250.00

Just in case someone's encountering the same problem also. :)

Try:

select concat(symbol, CONVERT(cast(format(closeprice,8) as char) USING utf8) COLLATE utf8_bin))

As you may not mix charset encoding in an CONCAT function like CONCAT(utf8_general_ci, utf8_bin).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM