MySQL REGEXP_LIKE() / REGEXP 함수
MySQL 8.0에서는 REGEXP_LIKE(), 그 이전버전에서는 REGEXP()로 이용할 수 있다.
mysql>SELECT * FROM COMTCCMMNDETAILCODE WHERE REGEXP_LIKE(CODE, '^b') ;
mysql>SELECT * FROM COMTCCMMNDETAILCODE WHERE code REGEXP '^b' ;
위 2개는 동일하다.
REGEXP_LIKE(expr, pat[, match_type])
와 같이 사용할 수 있다.
match_type 으로는 c, i, m, n, u 를 사용할 수 있다.
c : Case sensitive matching.
i : Case-insensitive matching. 따로 명시하지 않으면 i가 기본으로 적용되는 듯하다.
m : Multiple-line mode. Recognize line terminators within the string. The default behavior is to match line terminators only at the start and end of the string expression.
n : The . character matches line terminators. The default is for . matching to stop at the end of a line.
u : Unix-only line endings. Only the newline character is recognized as a line ending by the ., ^, and $ match operators.
mysql> SELECT CODE FROM COMTCCMMNDETAILCODE WHERE REGEXP_LIKE(CODE, '^B', 'c') ;
CODE column의 데이타가 "B"로 시작하는 것만 출력해준다.
아래와 같은 형태도 대소문자를 구별한다. binary 를 붙여준다.
mysql> SELECT REGEXP_LIKE('a', 'A'), REGEXP_LIKE('a', BINARY 'A'), REGEXP_LIKE('A', BINARY 'a'), REGEXP_LIKE('a', BINARY 'a') ;
+-----------------------+------------------------------+------------------------------+------------------------------+
| REGEXP_LIKE('a', 'A') | REGEXP_LIKE('a', BINARY 'A') | REGEXP_LIKE('A', BINARY 'a') | REGEXP_LIKE('a', BINARY 'a') |
+-----------------------+------------------------------+------------------------------+------------------------------+
| 1 | 0 | 0 | 1 |
+-----------------------+------------------------------+------------------------------+------------------------------+
1 row in set (0.01 sec)
^B와 같이 사용할 수 있는 정규표현식 구문들에 대해서는 아래 URL을 참조한다.