0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SQL書式設定-日付

0
Posted at

memo

事象

出力された日時がハイフン区切りで出力されてしまった。
ex) 2023-11-15

期待値

"/"区切りで出力されること
ex)2023/11/15

データ型書式設定 to_char

DBから取得したデータ型を指定のデータ型に変換することができる便利なツール

日付を指定の書式に変更

select to_char('2023-11-15', yyyy/mm/dd) from aiueo;

文字の切り取り left, right, substring

left:DBから取得した値を、入力数分を左から切り取る
right:DBから取得した値を、入力数分を右から切り取る
substring:DBから取得した値を、第1引数から第2引数分切り取る
select left('2023-11-15',4) || '/' || substring('2023-11-15',6,2) || '/' || right('2023-11-15',2) ;

参考

https://docs.oracle.com/cd/F19136_01/sqlrf/TO_CHAR-datetime.html#GUID-0C3EEFD1-AE3D-452D-BF23-2FC95664E78F
https://postgresweb.com/post-368

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?