MySQL using concat to splice Chinese characters garbled solution-fuxuejun column-Blog channel-Csdn.net http://blog.csdn.net/fuxuejun/article/details/6284725
MySQL concat garbled problem resolution concat (STR1,STR2) when the concat result set garbled, mostly because of the connection field type is different, such as the field parameter in the concat is a varchar type, an int type or doule type, It will appear garbled.
Workaround: Use the MySQL string conversion function convert to format the parameter as a char type. Example: Concat (' Quantity: ', convert (Int1,char), convert (Int2,char), ' Amount: ', convert (Double1,char), convert (Double2,char))
Postscript:
MySQL's cast () and CONVERT () functions can be used to get a value of one type and produce a value of another type. The specific syntax for both is as follows:
is cast (xxx as type), CONVERT (XXX, type).
There is a limit to the types that can be converted. This type can be one of the following values:
- Binary, with binary prefix effect: binary
- Character type, with parameters: CHAR ()
- Date: Date
- Time:
- DateTime Date/Time type
- Floating point number: DECIMAL
- Integer: Signed
- unsigned integer: UNSIGNED
Here are a few examples:
Example One
1 |
mysql> SELECT CONVERT ( ‘23‘ ,SIGNED); |
2 |
+ ----------------------+ |
3 |
| CONVERT ( ‘23‘ ,SIGNED) | |
4 |
+ ----------------------+ |
6 |
+ ----------------------+ |
Example Two
1 |
mysql> SELECT CAST ( ‘125e342.83‘ AS signed); |
2 |
+ ------------------------------+ |
3 |
| CAST ( ‘125e342.83‘ AS signed) | |
4 |
+ ------------------------------+ |
6 |
+ ------------------------------+ |
Example Three
1 |
mysql> SELECT CAST ( ‘3.35‘ AS signed); |
2 |
+ ------------------------+ |
3 |
| CAST ( ‘3.35‘ AS signed) | |
4 |
+ ------------------------+ |
6 |
+ ------------------------+ |
As in the example above, the varchar is converted to int with cast (a as signed), where a is a varchar-type string.
Example 4
In SQL Server, the following code demonstrates the result of a DateTime variable that contains only a single date and a simple time when the date stores the hexadecimal store representation.
05 |
SELECT CAST(@dt as binary(8)) |
06 |
--结果: 0x0000000100000000 |
10 |
SELECT CAST(@dt as binary(8)) |
11 |
--结果: 0x000000000000012C |
MySQL type conversion is like SQL Server, that is, the type parameter is a little different: CAST (xxx as type), convert (XXX, type).
MySQL using concat to splice Chinese characters garbled solution (GO)