MySQL 조 회 를 대소 문자 로 구분 하 는 실현 방법

1.한 가지 방법 은 표 나 줄 의 collation 을 설정 하여 binary 또는 case sensitive 로 만 드 는 것 입 니 다.MySQL 에서 Column Collate 에 대해 약 속 된 명명 방법 은 다음 과 같 습 니 다.*bin:binary case sensitive collation,즉 대소 문 자 를 구분 하 는*cs:case sensitive collation,대소 문자 구분*ci:case insensitive collation,대소 문자 구분 하지 않 음\#\#\#\#\#\#\#\#\#\#\#\#이 진 콜라 보 레이 션 예제\#\#\#\#\#\#\#\#\#\###\####mysql>테이블 케이스 만 들 기bin_test (word VARCHAR(10)) CHARACTER SET latin1 COLLATE latin1_bin; Query OK, 0 rows affected (0.02 sec) mysql> INSERT INTO case_bin_test VALUES ('Frank'),('Google'),('froogle'),('flickr'),('FlicKr'); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM case_bin_test WHERE word LIKE 'f%'; +---------+ | word | +---------+ | froogle | | flickr | +---------+ 2 rows in set (0.00 sec) mysql> SELECT * FROM case_bin_test WHERE word LIKE 'F%'; +---------+ | 워드|+---------+|Frank|FlicKr|+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------cs_test (word VARCHAR(10)) CHARACTER SET latin1 COLLATE latin1_general_cs; Query OK, 0 rows affected (0.08 sec) mysql> INSERT INTO case_cs_test VALUES ('Frank'),('Google'),('froogle'),('flickr'),('FlicKr'); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM case_cs_test WHERE word LIKE 'F%'; +---------+ | word | +---------+ | Frank | | FlicKr | +---------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM case_cs_test WHERE word LIKE 'f%'; +---------+ | 워드|+------+|froogle|flickr|+-----------------------------------------------------------------------------------------------------------------------------------------test (word VARCHAR(10)) CHARACTER SET latin1; Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO case_test VALUES ('Frank'),('Google'),('froogle'),('flickr'),('FlicKr'); Query OK, 7 rows affected (0.01 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM case_test WHERE word LIKE 'f%'; +---------+ | word | +---------+ | Frank | | froogle | | flickr | | FlicKr | +---------+ 6 rows in set (0.01 sec) mysql> SELECT * FROM case_test WHERE word LIKE 'F%'; +---------+ | word | +---------+ | Frank | | froogle | | flickr | | FlicKr | +---------+ 6 rows in set (0.01 sec) mysql> SELECT * FROM case_test WHERE word COLLATE latin1_bin LIKE 'F%'; +---------+ | word | +---------+ | Frank | | FlicKr | +---------+ 4 rows in set (0.05 sec) mysql> SELECT * FROM case_test WHERE word COLLATE latin1_bin LIKE 'f%'; +---------+ | word | +---------+ | froogle | | flickr | +---------+ 2 rows in set (0.00 sec) mysql> SELECT * FROM case_test WHERE word LIKE 'f%' COLLATE latin1_bin; +---------+ | word | +---------+ | froogle | | flickr | +---------+ 2 rows in set (0.00 sec) mysql> SELECT * FROM case_test WHERE word LIKE 'F%' COLLATE latin1_bin; +---------+ | word | +---------+ | Frank | | FlicKr | +---------+ 4 rows in set (0.01 sec) mysql> SELECT * FROM case_test WHERE word LIKE 'F%' COLLATE latin1_general_cs; +---------+ | word | +---------+ | Frank | | FlicKr | +---------+ 4 rows in set (0.04 sec)

좋은 웹페이지 즐겨찾기