所以我的表EMAILADDRESS VARCHAR2
中有一个LOCMEMBERS
字段。一些电子邮件地址以10位数的电话号码开头,我正在尝试识别那些电子邮件地址。所以我正在寻找标记5556667777@vtext.com
但不是10JamesDean@vtext.com
的方法。
这是一个Oracle DB。
我尝试了以下操作,但SUBSTRING
引发了错误“无效标识符”:
SELECT SUBSTRING(CAST(EMAILADDRESS AS VARCHAR(20)), 1, 10),
FROM LOCMEMBERS
答案 0 :(得分:1)
试试这个
WITH
locmembers(member_id, email_address) AS
(SELECT 1,'12345@rrr.com' FROM dual UNION ALL --numbers but < 10 digits
SELECT 2,'1122334455@rrr.com' FROM dual UNION ALL --numbers = 10 digits
SELECT 3,'112233445566@rrr.com' FROM dual UNION ALL --numbers > 10 digits
SELECT 4,'emailaddress@rrr.com' FROM dual UNION ALL
SELECT 5,'emailsaddress1122334455@rrr.com' FROM dual --email address with 10 digits
)
SELECT
member_id
,email_address
,SUBSTR(REGEXP_REPLACE(email_address, '^[[:digit:]]{10}' ),1,1)
FROM
locmembers
WHERE SUBSTR(REGEXP_REPLACE(email_address, '^[[:digit:]]{10}' ),1,1) = '@'
;