PostgreSQL 文字列を置換する
- 作成日 2022.08.13
- PostgreSQL
- PostgreSQL

PostgreSQLで、文字列を置換する手順を記述してます。
環境
- OS Rocky Linux release 8.4 (Green Obsidian)
- PostgreSQL 14.0
- pgadmin 6.0
文字列を置換
文字列を置換する場合は、「replace」を使用します。
replace( 文字列,検索文字列,置換文字列 )
実際に、「world」を「mebee」に置換してみます。
select replace('hello world','world','mebee')
実行結果

置換されていることが確認できます。
指定した文字列は全て置換されます。
select replace('hello world','l','e')
実行結果

存在しない値
また、存在しないものを置換の対象に選択してもエラーにはなりません。
select replace('hello world','!!','mebee')
実行結果

-
前の記事
PostgreSQL 時分秒から時刻を作成する 2022.08.13
-
次の記事
javascript エラー「Uncaught TypeError: Failed to execute ‘setAttribute’ on ‘Element’: 2 arguments required, but only 1 present.」の解決方法 2022.08.13
コメントを書く