时间:2021-07-01 10:21:17 帮助过:40人阅读
实现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;
?
?