I have created logic to fetch data from string field:
Input :
dbname,tblname,comment,tablekind
sample_1,table1,Test_SALES - SALES & PROD - Orders - flow - CORP - test_1@gmail.com -
test_2@gmail.com,T
sample_2,table2,Test_Finance - FS - PK - fs.global@GMAIL.com - fs1@gmail.com
Output :
dbname,tblname,domain,product,email
sample_1,table_1,Test_SALES,SALES & PROD,test_1@gmail.com;test_2@gmail.com
sample_2,table_2,Test_Finance,FS,fs.global@GMAIL.com;fs1@gmail.com
I have tried creating this query but getting error STRTOK: InputString or Delim length is 0; OR toknum parameter is no larger than 0 if comment is blank or null:
select dbname, tblname,comment,STRTOK(comment,'-',1) as domain,STRTOK(comment,'- ',2) as
product,
(cast(regexp_substr(comment, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b)', 1,
1, 'i') as varchar(128))
|| coalesce(',' ||cast(regexp_substr(comment, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-
Za-z]{2,6}\b)', 1, 2, 'i')as varchar(128)), '')
|| coalesce(',' ||cast(regexp_substr(comment, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-
Za-z]{2,6}\b)', 1, 3, 'i')as varchar(128)), '')
|| coalesce(',' ||cast(regexp_substr(comment, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-
Za-z]{2,6}\b)', 1, 4, 'i')as varchar(128)), '')
|| coalesce(',' ||cast(regexp_substr(comment, '(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-
Za-z]{2,6}\b)', 1, 5, 'i')as varchar(128)), '')) as email
from dbc.tables where tablekind in ('T','V')