仅从列中获取字符记录
Get only character records from column
Table:
create table tbl_prefix
(
col_pre varchar
);
记录:
insert into tbl_prefix values
('Mr.'),('Mrs.'),('Ms.'),('Dr.'),
('Jr.'),('Sr.'),('II'),('III'),
('IV'),('V'),('VI'),('VII'),
('VIII'),('I'),('IX'),('X'),
('Officer'),('Judge'),('Master');
预期输出:
col_pre
----------
Mr.
Mrs.
Ms.
Dr.
Jr.
Sr.
Officer
Judge
Master
尝试:
select *
from tbl_prefix
where col_pre ~ '[^a-zA-Z]'
获得:
col_pre
----------
Mr.
Mrs.
Ms.
Dr.
Jr.
Sr.
这里的一种方法可能是匹配任何不是罗马数字的前缀:
SELECT *
FROM tbl_prefix
WHERE col_pre !~ '^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$';
这里用于罗马数字的正则表达式模式来自这个 SO 问题:
How do you match only valid roman numerals with a regular expression?
Table:
create table tbl_prefix
(
col_pre varchar
);
记录:
insert into tbl_prefix values
('Mr.'),('Mrs.'),('Ms.'),('Dr.'),
('Jr.'),('Sr.'),('II'),('III'),
('IV'),('V'),('VI'),('VII'),
('VIII'),('I'),('IX'),('X'),
('Officer'),('Judge'),('Master');
预期输出:
col_pre
----------
Mr.
Mrs.
Ms.
Dr.
Jr.
Sr.
Officer
Judge
Master
尝试:
select *
from tbl_prefix
where col_pre ~ '[^a-zA-Z]'
获得:
col_pre
----------
Mr.
Mrs.
Ms.
Dr.
Jr.
Sr.
这里的一种方法可能是匹配任何不是罗马数字的前缀:
SELECT *
FROM tbl_prefix
WHERE col_pre !~ '^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$';
这里用于罗马数字的正则表达式模式来自这个 SO 问题:
How do you match only valid roman numerals with a regular expression?