我有一个存储过程,它将字符串分开并以select结尾。带INSERT的MySQL INSERT
我想在存储过程运行的插件像你这样在选择
像这样的事情
INSERT INTO ....
CALL sp_split...
我的分裂做插入看起来是这样的:
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `split_with_id`(id INT, input varchar(1000), delim VARCHAR(10))
BEGIN
declare foundPos tinyint unsigned;
declare tmpTxt varchar(1000);
declare delimLen tinyint unsigned;
declare element varchar(1000);
drop temporary table if exists tmpValues;
create temporary table tmpValues
(
`id` int not null default 0,
`values` varchar(1000) not null default ''
) engine = memory;
set delimLen = length(delim);
set tmpTxt = input;
set foundPos = instr(tmpTxt,delim);
while foundPos <> 0 do
set element = substring(tmpTxt, 1, foundPos-1);
set tmpTxt = replace(tmpTxt, concat(element,delim), '');
insert into tmpValues (`id`, `values`) values (id, element);
set foundPos = instr(tmpTxt,delim);
end while;
if tmpTxt <> '' then
insert into tmpValues (`id`, `values`) values (id, tmpTxt);
end if;
select * from tmpValues;
END
我相信这个问题可能是你想要实现http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure – Robb 2012-02-07 16:06:51
这是一个格栅文章对于MS SQL,但不幸的是,MySQL不支持exec – esack 2012-02-07 20:37:58