這裏CTE只是爲了解決這個問題。第一步是創建一個包含解析列表元素的CTE「表」。然後從中選擇。 CTE正則表達式處理NULL列表元素。
with main_tbl(email) as (
select ' [email protected] , [email protected], [email protected],[email protected], [email protected] , [email protected], [email protected], foobar '
from dual
),
email_list(email_addr) as (
select trim(regexp_substr(email, '(.*?)(,|$)', 1, level, NULL, 1))
from main_tbl
connect by level <= regexp_count(email, ',')+1
)
-- select * from email_list;
select LISTAGG(TRIM(email_addr), ', ') WITHIN GROUP (ORDER BY email_addr)
from email_list
where lower(email_addr) like '%gmail.com';
使用像%gmail.com作爲選擇*從Table_name其中電子郵件像%gmail.com –
修復您的數據模型。不要將列表存儲在字符串中。這不是存儲列表的SQLish方式。 –
使用REPLACE_REGEXP函數,您將在其中定義匹配要過濾的域的表達式並將其替換爲空字符串 –