当前位置:网站首页>Complete review (including syntax) -- MySQL regular expressions

Complete review (including syntax) -- MySQL regular expressions

2022-06-26 01:25:00 Mixed with bean curd and

Complete review of regular expressions ( Including grammar )

– Regular expression data is from the previous chapter MyBingSchool In the library
use MyBingSchool;
– Student information sheet
SELECT * FROM Student;
– Subject list
select * from Cuosre;
– Score table
select * from Sorce;
– Teachers list
select * from Teacher;

– Regular expressions Operation cases

– ^ Matches the start of the input string With 1 Starting data


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '^1'  ORDER BY s_brith ;

– ^ Matches the end of the input string With 9 Starting data

-- select s_sroce as ' fraction ' from Sorce WHERE s_sroce REGEXP '^9'  ORDER BY s_sroce ;

select s_sroce as ' fraction ' from Sorce WHERE s_sroce REGEXP '9$'  ORDER BY s_sroce ;

select s_name as  ' full name ' from student WHERE s_name REGEXP ' Four $'  ORDER BY s_name;

select s_name as  ' full name ' from student WHERE s_name REGEXP '^[ Zhang ]| Two &'  ORDER BY s_name;

– . Match any character .9 Here match any containing 9 The data of


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '.9'  ORDER BY s_brith;

– .4 Here match any containing 4 The data of


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '.4'  ORDER BY s_brith;

– | And ‘or’ similar perhaps Match, so


select s_name as  ' full name ' from student WHERE s_name REGEXP ' Zhang San | The king 2 | Li Si '  ORDER BY s_name;

– Lookup table with 199 1996 1998 The data of ‘’=LIKE It has the function of fuzzy query conditions


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '199'  ORDER BY s_brith ;

select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '1996'  ORDER BY s_brith ;

select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '1998'  ORDER BY s_brith ;

– Combine [] Matching condition | perhaps


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '199[6|8]'  ORDER BY s_brith ;

– * Match previous subexpression zero or more times * Equivalent to {0,}


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '1*'  ORDER BY s_brith ;

– Match previous subexpression one or more times + Equivalent to {1,}


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '1+'  ORDER BY s_brith ;

– Combine ^ + Use


select s_sroce as ' fraction ' from Sorce WHERE s_sroce REGEXP '^9+'  ORDER BY s_sroce ;

– {n} n Is a non negative integer . Matched definite n Time 9{2}


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '9{2}'  ORDER BY s_brith ;

– {n,m} m and n All non negative integers among n <= m Least match n Times and at most m Time
– Insert data for easy demonstration {n,m}


INSERT INTO student VALUES (DEFAULT,' Liu tao ',' Woman ','1999-01-11');

– Auto increment cannot be used without setting default
– Modify the insert data according to the name


UPDATE student set s_id='06' WHERE s_name=' Liu tao ';

INSERT INTO student VALUES ('07',' Wang Tao ',' Woman ','1999-02-22');

INSERT INTO student VALUES ('08',' Xiao Xiao ',' Woman ','1888-08-18');


select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '9{1,3}'  ORDER BY s_brith ;

select s_brith as ' date of birth ' from student WHERE s_brith REGEXP '9{2,3}'  ORDER BY s_brith ;

原网站

版权声明
本文为[Mixed with bean curd and]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206252353285206.html