declare myvar int(11); in mysql routine returns syntax error
I had a very long routine that used to work on a previous server. I migrated it to a new server and I started having sql syntax error.
So I did a test:
create procedure test()
begin
declare myvar int(11);
sele开发者_如何学Cct myvar;
end
By running this in mysql or in Mysql Workbench you should have a syntax error at 11) just before the ;
What's going on!
I've looked at mysql references on the subject they say declare [variablename] [datatype]
I've tried with other data types just to make sure I still get the same problem.
thanks in advance for your help.
When you declare variables you don't give them display lengths. Those numbers are meant for table column definitions only.
Just do
DECLARE myvar INT;
Additionally declare would be first statement after begin. otherwise this will always give error.
精彩评论