[SQLite] CASTで型変換

eyecatch SQLiteで型を変換するのは、CAST関数を使います。

日付変換

- ハイフン区切り SELECT cast("2024/1/1" as DATE) as date > "2024-01-01" - アンダースコア区切り SELECT cast("2024_1_1" as DATE) as date > "2024-01-01" - 半角スペース区切り(変換されない) SELECT cast("2024 1 1" as DATE) as date > null - %区切り SELECT cast("2024%1%1" as DATE) as date > "2024-01-01" - 日本語表記(変換されない) SELECT cast("2024年1月1日" as DATE) as date > null - UTC表記 SELECT cast("2024-01-01 00:00:00 UTC" as DATE) as date > "2024-01-01"

文字列→数値

- INTEGER(変換されない) SELECT cast("001" as INTEGER) as num > null - FLOAT SELECT cast("001" as FLOAT) as num > 1 - DOUBLE SELECT cast("001" as DOUBLE) as num > 1