Home > Database > Mysql Tutorial > 实现mysql 的瓜分字符功能

实现mysql 的瓜分字符功能

WBOY
Release: 2016-06-07 16:15:43
Original
1024 people have browsed it

实现mysql 的分割字符功能 DROP PROCEDURE IF EXISTS db_test.proc_test;create PROCEDURE proc_test()BEGINdeclare b varchar(500);declare sqls varchar(1000); set b='123;234;567;789'; DROP table IF EXISTS splittable;CREATE TEMPORARY TABLE splittab

实现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;
Copy after login

?

?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template