mysql - using the condition if in a function -
i created function using "if..else if", in order cover field , extract characters , store them in column:
delimiter | create function mettre (s varchar(2000)) returns varchar(10000) deterministic begin declare str varchar(2000); declare str1 varchar(2000); declare str2 varchar(2000); declare str3 varchar(2000); declare tofind varchar(2000); declare co varchar(2000); set co=''; set str=''; set str1=''; set str2=''; set str1 =substring(trim(substring_index(s,'du',-1)),1,3); set str2 =substring(trim(substring_index(s,':',-1)),1,3); set str =substring(trim(substring_index(s,'sur',-1)),1,3); if (str in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab')) =1 set co = str ; else if ((str not in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab')) , (str1 in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab')))=1 set co = str1 ; else if ((str1 not in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab'))and (str2 in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab')))=1 set co = str2 ; else set co = '1' ; end if; end if; end if; return co; end | delimiter;
but it's not working first condition used.
if (str in ('zag','tun','toz','tat','sos','sil','sfx','sbo','rnc','bar','bej','biz','bsc','gab','gaf','jen','kai','kas','keb','kef','mah','med','mon','nab')) =1 set co = str ;
Comments
Post a Comment