[Sqlite] 결과 숫자를 두 자리로 표현할때 빈곳은 0으로 채우기 - printf(), with
결과 숫자를 두 자리로 표현할때 빈곳은 0으로 채우기
SQL Function - printf()
C 라이브러리의 printf() 함수 처럼 사용할 수 있다.
문제
결과값
1, 2, 3
숫자를 두자리로 표현 하는데 한자리 숫자는 앞에 0을 채워주고 싶을때
'01', '02', 03
사용예
sqlite> with table as (
...> select 1 as col1
...> union all
...> select 2 as col1
...> union all
...> select 3 as col1
...> )
...> select printf('%02d', col1) from table;
01
02
03
출처
sqlite 공식 문서 - Built-In Scalar SQL Functions
sqlite.org/lang_corefunc.html#printf
printf(FORMAT,...)
The printf(FORMAT,...) SQL function works like the sqlite3_mprintf() C-language function and the printf() function from the standard C library. The first argument is a format string that specifies how to construct the output string using values taken from subsequent arguments. If the FORMAT argument is missing or NULL then the result is NULL. The %n format is silently ignored and does not consume an argument. The %p format is an alias for %X. The %z format is interchangeable with %s. If there are too few arguments in the argument list, missing arguments are assumed to have a NULL value, which is translated into 0 or 0.0 for numeric formats or an empty string for %s. See the built-in printf() documentation for additional information.
글이 유용하셨다면 광고 한번만 클릭 부탁드립니다. 광고 클릭수가 하루 한건도 안나와서 글 올리는 재미가 없어요.
이걸 본 당신의 하루에 행운이 가득하기를 바랍니다. ^^