如何在存储过程中进行split操作
原理:循环调用SPLIT_SUB_STR
示例代码如下:
sp_SaveRole
参数IN `myrolename` varchar(64),IN `mypermission` varchar(512)
BEGIN
declare _rolename varchar(64);
declare _roleid int default 0;
declare _permission varchar(512);
declare _splititem varchar(64);
set _rolename = myrolename;
set _permission = mypermission;
set _roleid = 0;
insert into sys_roles(name) values(_rolename);
select roleid into _roleid from sys_roles order by roleid desc limit 1;
REPEAT
CALL SPLIT_SUB_STR(_permission, ',', _splititem);
insert into sys_rolepermissions (roleid, permissionid) values(_roleid, _splititem);
UNTIL _permission = ''
END REPEAT;
END
这里根据参数分解mypermission,split写入表中
输入为'员工','1,2'