1. SUBSTRING
SUBSTRING( 문자열, 시작위치, 길이 )
- 문자열: 문자를 자르기 위한 전체문자
- 시작위치: 1부터 첫번째 글자로 시작합니다.
- 길이: 시작위치로부터 길이까지 문자열을 자릅니다.
예시 ( 기본 )
SELECT SUBSTRING('가나다라마바사' , 1, 3); -- 가나다
SELECT SUBSTRING('가나다라마바사' , 2, 2); -- 나다
SELECT SUBSTRING('가나다라마바사' , 3, 1); -- 다
예시 ( 마지막 문자까지 )
-- address 컬럼에 '서울특별시 마포구 희우정로'라고 있다고 가정.
SELECT SUBSTRING(address , 7, LENGTH(address)); -- 마포구 희우정로
2. SPLIT_PART
SPLIT_PART( 문자열, 구분문자, 위치 )
- 문자열: 문자를 구분하기 위한 전체문자입니다.
- 구분문자: 구문문자로 구분해서 나눕니다.
- 위치: 구분된 문자 위치 (예: 010-1234-1234 를 - 로 구분하면 [010, 1234, 1234]로 구분되며 이때 위치 1은 010이 됩니다.)
예시
SELECT SPLIT_PART('010-1234-1234', '-', 1); -- 010
SELECT SPLIT_PART('010-1234-5678', '-', 2); -- 1234
SELECT SPLIT_PART('010-1234-5678', '-', 3); -- 5678
3. REPLACE
REPLACE( 소스, 이전 문자, 새로운 문자 )
- 소스: 재배치할 전체 문자입니다.
- 이전 문자: 재배치를 진행할 이전 문자입니다.
- 새로운 문자: 이전 문자를 새로운 문자로 재배치합니다.
예시
SELECT REPLACE( '가 나 다', ' ', '' ); -- 가나다
SELECT REPLACE( '가나다라1마바사', '1', '' ); -- 가나다라마바사
SELECT REPLACE( '가나다3마바사', '3', '라' ); -- 가나다라마바사
SELECT REPLACE( '1212124', '12', '' ); -- 4
참조
[PostgreSQL functions-string]: https://www.postgresql.org/docs/9.1/functions-string.html
String Functions and Operators
This section describes functions and operators for examining and manipulating string values. Strings in this context include values of the types character, character varying, and text. Unless otherwise noted, all of the functions listed below work on all o
www.postgresql.org
[PostgreSQL Tutorial]: https://www.postgresqltutorial.com/postgresql-string-functions/postgresql-substring/
PostgreSQL Substring - Extracting a substring from a String
Summary: in this tutorial, we will introduce you to PostgreSQL substring function that extracts a substring from a string. Introduction to PostgreSQL substring function The substring function returns a part of string. The following illustrates the syntax o
www.postgresqltutorial.com
'Database > PostgreSQL' 카테고리의 다른 글
[PostgreSQL] with문 사용하기 (CTE) (0) | 2023.04.12 |
---|---|
[PostgreSQL] INSERT INTO SELECT (0) | 2023.04.10 |
[PostgreSQL] 데이터베이스 생성 (0) | 2023.02.16 |
[PostgreSQL] 날짜 관련 상황별 정리 (0) | 2022.09.23 |
[PostgreSQL] DROP COLUMN (0) | 2022.07.13 |
댓글