C.W.K.
Stream
Lesson 09 of 10 · published

쓸모 있는 String 함수

~12 min · sql, strings, functions

Level 0Scout
0 XP0/80 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

실제로 호출할 12 개

SQLite 가 작지만 실용적인 string 함수 set 제공. 챙길 거:

  • length(s) — TEXT 면 char count, BLOB 면 byte count.
  • upper(s), lower(s) — 기본 ASCII case 만.
  • trim(s), ltrim(s), rtrim(s) — whitespace (또는 지정 char) 제거.
  • substr(s, start, len) — 1-indexed slicing.
  • replace(s, old, new) — substring replace.
  • instr(s, sub)s 에서 sub 의 1-indexed 위치, 못 찾으면 0.
  • printf('%s says %s', a, b) — C 스타일 포맷팅.
  • || — concat 연산자.
  • group_concat(col, sep) — 집계 concat.
  • hex(blob), quote(s) — binary 검사 또는 안전 quoting.
Warning: upper/lower 는 기본 ASCII A–Z 만. upper('한글') 은 변경 없이 '한글' 반환. Unicode-correct case folding 은 ICU extension 필요 (앱 코드엔 거의 안 쓰는 게 나음, casing 은 Python 에서).

Code

String 함수 실전·sql
SELECT email,
       length(email)                 AS n,
       substr(email, 1, instr(email, '@') - 1) AS local_part,
       substr(email, instr(email, '@') + 1)   AS domain,
       printf('%s -> %s', username, email) AS pretty
FROM users;

External links

Exercise

테이블의 free-form text 컬럼에서 derived 컬럼 5 개 작성: length, lowercased, trimmed, 첫 단어 (첫 공백까지), printf 포맷 display string. Edge case (빈 string, 공백 없음, 앞 whitespace, Unicode) 동작 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.