开发者

declare myvar int(11); in mysql routine returns syntax error

开发者 https://www.devze.com 2023-02-05 18:17 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号