[MySQL]CAST 関数で指定した値を別のデータ型に変換

2021年12月30日

書式1
CAST(expr AS type)
CAST 関数は引数に指定した値を別のデータ型に変換します

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select cast(now() as signed) result;
実行結果
result
20211230035001
select cast(now() as signed) result; 実行結果 result 20211230035001
select cast(now() as signed) result;
実行結果
result
20211230035001

書式2
CONVERT(expr,type)
CONVERT 関数は引数に指定した値を別のデータ型に変換します

使用例2

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select convert(now(), signed) result2;
実行結果
result2
20211230035207
select convert(now(), signed) result2; 実行結果 result2 20211230035207
select convert(now(), signed) result2;
実行結果
result2
20211230035207

 

MySQL

Posted by arkgame