- position(substring in string)
select position('aa' in 'abcd'); position ---------- 0 (1 row) select position('ab' in 'abcd'); position ---------- 1 (1 row) select position('ab' in 'abcdab'); position ---------- 1 (1 row)
select a.* from ls_emp_info a left join ls_emp_post b on a.id = b.emp_id -- 判断字符串是否包含 -- where position( '2' in b.post_no) > 0; where position( #{empInfo.postNo} in b.post_no) > 0;
- strpos(string, substring): 声明子串的位置
select strpos('abcd','aa'); strpos -------- 0 (1 row) select strpos('abcd','ab'); strpos -------- 1 (1 row) select strpos('abcdab','ab'); strpos -------- 1 (1 row)
- 正则表达式
select 'abcd' ~ 'aa'; ?column? ---------- f (1 row) select 'abcd' ~ 'ab'; ?column? ---------- t (1 row) select 'abcdab' ~ 'ab'; ?column? ---------- t (1 row)
- 使用数组的@>操作符
不能准确判断是否包含
select regexp_split_to_array('abcd','') @> array['b','e']; ?column? ---------- f (1 row) select regexp_split_to_array('abcd','') @> array['a','b']; ?column? ---------- t (1 row)
select regexp_split_to_array('abcd','') @> array['a','a']; ?column? ---------- t (1 row) select regexp_split_to_array('abcd','') @> array['a','c']; ?column? ---------- t (1 row) select regexp_split_to_array('abcd','') @> array['a','c','a','c']; ?column? ---------- t (1 row)
数组的包含操作符判断的时候不管顺序、重复,只要包含了就返回true