RLIKEを使用して、データの文字列の後に特定の文字または文字列の終わり($)が続く場所を照合しようとしています。文字列の終わり($)だけ、期待される文字、または角かっこ内の期待される文字のセットを使用して期待される結果が得られますが、期待される文字ORと終わりの角かっこに入るとすぐに文字列文字、行末が一致していません。
次に例を示します。
SQLデータ:
CREATE TABLE test_table (id int auto_increment primary key, search_string varchar(8));
INSERT INTO test_table (search_string) VALUES("123456789");
INSERT INTO test_table (search_string) VALUES("1234567");
INSERT INTO test_table (search_string) VALUES("123456");
INSERT INTO test_table (search_string) VALUES("12345");
INSERT INTO test_table (search_string) VALUES("12345E");
このデータに対するクエリの例:
SELECT count(*) FROM test_table WHERE search_string RLIKE "56[7]";
# the above returns fine - 2 rows (first and second)
SELECT count(*) FROM test_table WHERE search_string RLIKE "56[7YE]";
# the above returns fine - 2 rows (rows 2 and 5) as expected
SELECT count(*) FROM test_table WHERE search_String RLIKE "56$";
# the above returns fine - 1 rows (the third) as expected as 6 is followed by end of string
SELECT count(*) FROM test_table WHERE search_string RLIKE "56[7$]";
# the above returns only 1 row and should be 2 (rows 2 and 3 - '56' should be followed by a 7 or end of string)
$文字が角かっこで囲まれている場合にそれを処理する特別な方法はありますか?