日期:2014-05-16  浏览次数:20781 次

实现mysql 的分割字符功能
DROP PROCEDURE IF EXISTS db_test.proc_test;

create PROCEDURE proc_test()
BEGIN
		declare b varchar(500);
		declare sqls varchar(1000);
	  set b='123;234;567;789'; 
		DROP table IF EXISTS splittable;
		CREATE TEMPORARY TABLE splittable(
				id INT AUTO_INCREMENT primary key,
				VALUE VARCHAR(20)
		);
		set sqls=concat("insert into splittable(value) values ('",replace(b,';',"'),('"),"')"); 
		select sqls;
		SET @sql=sqls;  #必须这样转一样
		prepare stem from @sql;
		execute stem;
		DEALLOCATE PREPARE stem;
		select * from splittable;
end;

?

?