SQL(Scalar Functions)

김혜민·2024년 2월 14일

SQL

목록 보기
12/21

Scalar Functions

  • 입력값을 기준으로 단일 값을 반환하는 함수

1. Ucase

select Ucase(string);

2. Lcase

select Lcase(string);

3. Mid

select mid(string, start_position, length);
  • string 원본 문자열
  • start_position 문자열 반환 시작위치(첫글자는 1, 마지막 글자는 -1)
    ex)-1이면 뒤에서부터 1번째 위치
  • length 반환할 문자열 길이

4. Length

select length(string);
  • 공백도 1글자로 여김
    ex) 성재 사랑해 -> length = 6
    ' ' -> length = 1
    * null은 길이가 없으므로 length치면 null로 나옴!

5. Round

select round(number,decimals_place);
  • number 반올림할 대상
  • decimlas_place 반올림할 소수점 위치
  • 반올림할 위치를 지정하지 않을 경우 소수점 자리(0)에서 반올림!
    ex) select round(220.719) = 221
    select round(220.719,1) = 220.7
  • 1단위 위치는 -1
    ex) select round(220.719,-1) = 220

6. Now

select now();

7. Format

select format(number,decimals_place);
  • number 포맷을 적용할 숫자 혹은 문자
  • decimlas_place 표시할 소수점 위치
  • 소수점을 표시하지 않을 경우 0
    ex) select format(12345.6789,0) = 12,346 / select format(12345.6789,2) = 12,345.68
  • 소수점 자리보다 표시할 소수점 위치가 더 많을 땐 0으로 표시
    ex) select format(12345.6789,10) = 12,345.6789000000
profile
성장하는 주니어 데이터 분석가입니다!

0개의 댓글