BookmarkSubscribeRSS Feed

SQL - 문자열 함수 변환 2

Started ‎01-29-2025 by
Modified ‎01-29-2025 by
Views 1,003

 

■ TRIM: 문자열 공백 제거

 

  • LTRIM: 문자열의 왼쪽(앞) 공백을 제거합니다.

  • RTRIM: 문자열의 오른쪽(뒤) 공백을 제거합니다.

  • TRIM: 양쪽 공백을 제거합니다.

 

 

# LTRIM 예제

 

SELECT'  With great power comes great responsibility.',
LTRIM('   With great power comes great responsibility.');

 

image (2).png

 

 

 

#RTRIM 예제

 

SELECT'I want to choose my own path.   ',
RTRIM('I want to choose my own path.    ');

 

image (3).png

 

 

 

 

#TRIM 예제

 

SELECT'     It’s hard for a good man to be a king.    ',
TRIM('     It’s hard for a good man to be a king.    ');

 

image.png

 

 

 

 

■ LENGTH

LENGTH 는 문자열의 크기를 바이트로 반환합니다.

 

SELECT 
LENGTH('Hope is the greatest of the gifts well receive.')

 

image (1).png

 

 

 

 

 

 

■ CHAR_LENGTH

문자열의 개수를 반환합니다.

 

SELECT 
CHAR_LENGTH('Hope is the greatest of the gifts well receive.')

 

 

 

 

■ POSITION

지정한 특정 문자까지의 길이를 반환합니다.

 

SELECT 
'Hope is the greatest of the gifts well receive.',
POSITION('is' IN 'Hope is the greatest of the gifts well receive.');

 

 

 

■ LEFT, RIGHT

문자열 왼쪽이나 오른쪽에서 시작해 정의한 위치까지 문자열을 반환합니다.

문자열의시작 위치는 1입니다.

 

SELECT
'Past is just past.',
LEFT('Past is just past.',4),
RIGHT('Past is just past.',4);

 

 

 

 

■ SUBSTR

지정한 범위의 문자열을 반환합니다.

예를 들어 아래의 예시는 'Past is just past.' 문장에서 6번째 문자부터 시작해 4개의 문자를 추출하는 예시입니다.

 

SELECT
'Past is just past.',
substr('Past is just past.', 6,4);

 

 image (2).png

 

 

 

 

 

■ REPLACE

지정 문자를 다른 문자로 대체하는 함수입니다.

 

SELECT
'No sweat, No sweet.',
REPLACE('No sweat, No sweet.','SWEAT','PAIN');

image (3).png

 

 

 

■ REVERSE

문자열을 역순으로 정렬합니다.

SELECT
'No pain, No gain@',
reverse('No pain, No gain@');

 

 

 

 

Contributors
Version history
Last update:
‎01-29-2025 06:44 AM
Updated by:

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Article Labels
Article Tags