在我的例子中,我想允许邮件在@
之后有两个或多个点,如test@test1.test2.com
。
我想在SQL中做,然后在Oracle和PostgreSQL中测试。
如果有人知道如何在SQL中使用正则表达式,请帮助。
我已经这样做了——这是正确的吗?
[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]
这里有一个选项:计数@
符号后的点数:
SQL> with test (col) as
2 (select 'test@test1.test2.com.' from dual)
3 select regexp_count(substr(col, instr(col, '@')), '.') number_of_dots
4 from test;
NUMBER_OF_DOTS
--------------
3
SQL>
使用
SQL> with test (col) as
2 (select 'test@test1.test2.com.' from dual union all
3 select 'another@test.com' from dual
4 )
5 select col,
6 case when regexp_count(substr(col, instr(col, '@')), '.') >= 2 then 'OK'
7 else 'wrong'
8 end result
9 from test;
COL RESULT
--------------------- --------------------
test@test1.test2.com. OK
another@test.com wrong
SQL>