刚刚在ubuntu 21.04上安装了sql。
$ mysql -V
mysql Ver 8.0.26-0ubuntu0.21.04.3 for Linux on x86_64 ((Ubuntu))写了一个test.sql文件:
declare @a as int=4在命令行上执行mysql> source /home/home/test.sql时,返回以下错误:
ERROR 1064 (42000): 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 'declare @a as int=4' at line 1向脚本添加begin和end也无济于事。修复方法是什么?
发布于 2021-08-11 21:01:10
只能在存储过程中使用声明的变量。在普通的SQL脚本中,使用用户变量,它们是以@开头的名称。您不需要指定类型,它们可以保存任何类型的值。
SET @a = 4;发布于 2021-08-12 00:46:36
首先,您需要声明变量
DECLARE @MyVariable INT;然后你可以设置它
SET @MyVariable = 1;https://stackoverflow.com/questions/68748859
复制相似问题