如果是Oracle数据库的话,下面这个触发器就可以用了:
create or replace trigger Test
before insert on Table0
for each row
declare
v_Name varchar2(200);
I Integer;
function GetSubStr(
p_Str varchar2,
p_Index number,
p_Separator varchar2 default ',')
return varchar2 is
P1 number;
P2 number;
SepLen number;
TmpStr varchar2(32767);
AddTail boolean;
begin
if p_Index < 1 then
return NULL;
end if;
SepLen := LENGTH(p_Separator);
TmpStr := LTRIM(RTRIM(p_Str));
AddTail :=
LENGTH(LTRIM(RTRIM(TmpStr))) > 0
and SUBSTR(TmpStr, LENGTH(TmpStr) - SepLen + 1, SepLen) <> p_Separator;
if AddTail then
TmpStr := TmpStr || p_Separator;
end if;
if p_Index = 1 then
P1 := 0;
else
P1 := INSTR(TmpStr, p_Separator, 1, p_Index - 1);
end if;
P2 := INSTR(TmpStr, p_Separator, 1, p_Index);
return LTRIM(RTRIM(SUBSTR(TmpStr, P1 + 1, P2 - P1 - 1)));
exception
when others then
return NULL;
end GetSubStr;
begin
I := 1;
loop
v_Name := GetSubStr
New.SendTo, I);
exit when v_Name is null;
insert into Table1(UserID, ID) values(v_Name, 生成你的ID);
end loop;
end Test;