亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

mysql數據類型轉換

mysql數據類型轉換

吃雞游戲 2019-05-11 07:07:15
mysql數據類型轉換
查看完整描述

3 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

數字轉字符

mysql> SELECT CONCAT ( CAST(1 as char) , '2') AS test;

+------+

| test |

+------+

| 12   |

+------+

1 row in set (0.00 sec)

 

mysql> SELECT CONCAT ( Convert(1, char) , '2') AS test;

+------+

| test |

+------+

| 12   |

+------+

1 row in set (0.00 sec)

 

字符轉數字

mysql> SELECT CAST('1' as SIGNED) + 100 AS test;

+------+

| test |

+------+

|  101 |

+------+

1 row in set (0.00 sec)

 

mysql> SELECT Convert('1' , SIGNED) + 100 AS test;

+------+

| test |

+------+

|  101 |

+------+

1 row in set (0.00 sec)





查看完整回答
反對 回復 2019-05-12
?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

CONVERT() provides a way to convert data between different character sets. The syntax is:

CONVERT(expr USING transcoding_name)

In MySQL, transcoding names are the same as the corresponding character set names.

Examples:

SELECT CONVERT(_latin1'Müller' USING utf8);
INSERT INTO utf8table (utf8column)
SELECT CONVERT(latin1field USING utf8) FROM latin1table;

CONVERT(... USING ...) is implemented according to the standard SQL specification.

You may also use CAST() to convert a string to a different character set. The syntax is:

CAST(character_string AS character_data_type CHARACTER SET charset_name)

Example:

SELECT CAST(_latin1'test' AS CHAR CHARACTER SET utf8);

If you use CAST() without specifying CHARACTER SET, the resulting character set and collation are defined by the character_set_connection and collation_connection system variables. If you use CAST() with CHARACTER SET X, the resulting character set and collation are X and the default collation of X.

You may not use a COLLATE clause inside a CAST(), but you may use it outside. That is, CAST(... COLLATE ...) is illegal, but CAST(...) COLLATE ... is legal.

Example:

SELECT CAST(_latin1'test' AS CHAR CHARACTER SET utf8) COLLATE utf8_bin;






查看完整回答
反對 回復 2019-05-12
  • 3 回答
  • 0 關注
  • 885 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號