该代码正在通过 MySQL Workbench 验证器,但根本不起作用。有人可以帮我解答一下吗?
它所做的只是在执行失败后抛出此错误。
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1
drop procedure if exists dividir_tabla_por_usuario;
delimiter //
create procedure dividir_tabla_por_usuario(tabla varchar(100), columna_usuario varchar(100), columna_fecha varchar(100))
begin
set @i = 0;
set @q1 = concat('select count(*) from (select distinct ', columna_usuario ,' from ', tabla , ' order by ', columna_usuario ,' asc) as t1 into @c');
prepare p1 from @q;
execute p1;
while @i <= @c do
set @r = 0;
set @q2 = concat('select * from ', tabla , ' where ', columna_usuario ,' = (select ', columna_usuario ,' from (select @r:=@r +1 as ord, ', columna_usuario ,' from (select distinct ', columna_usuario ,' from ', tabla , ' order by ', columna_usuario ,' asc) as t2) as t3 where ord = ', @i ,' ) order by ', columna_fecha ,' asc limit 30000');
prepare p2 from @q2;
execute p2;
set @i := @i + 1;
end while;
end//
delimiter ;
call dividir_tabla_por_usuario('mytable', 'mycolumn1', 'mycolumn2');
感谢您的关注。
最佳答案
尝试改变:
...
/* prepare p1 from @q; */
PREPARE p1 FROM @q1;
...
关于MySQL 5.6 程序通过 Workbench 的验证器但无法工作,错误代码 : 1064,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21974441/