在SQL中声明@变量返回错误
I am trying to declare a variable in SQL. I Have tried both
我试图在SQL中声明一个变量。我试过了两个
declare @mean INT;
set @mean = .5;
and
declare @mean INT
set @mean = .5
I keep getting this error:
我一直收到这个错误:
An unexpected token "" was found following "". Expected tokens may include: "declare @mean INT"
在“”之后发现了一个意外的标记“”。预期的代币可能包括:“声明@mean INT”
2 个解决方案
#1
If you want to declare your variable as a loosely-typed user-defined variables are defined using '@', you can simply go:
如果要将变量声明为松散类型,则使用“@”定义用户定义的变量,您只需:
SET @mean := .5
If not, then perhaps you want to define a variable in a stored procedure, then you can perhaps define as follows:
如果没有,那么也许你想在存储过程中定义一个变量,那么你可以定义如下:
DECLARE mean INT;
SET mean = .5; // not sure you mean INT here though?
You may find this SO link useful for describing the differences in my sql variables. Also check out the mysql manual(user variables) / (local variables).
您可能会发现此SO链接对于描述我的sql变量的差异很有用。另请查看mysql手册(用户变量)/(局部变量)。
I think some of the confusion here may stem from the differing syntax that T-SQL uses from Mysql, but read the above link and use whatever method suits you best.
我认为这里的一些混淆可能源于T-SQL在Mysql中使用的不同语法,但请阅读上述链接并使用适合您的最佳方法。
更多相关文章
- MySQL查询中的变量会导致错误
- 如何检查变量是否与fetch()具有相同的值
- PHP OOP和MySQLi连接=致命错误:调用未定义的方法sqmyli::arrayQu
- 如何将sql查询中的值存储到变量中?
- MySQL 自定义函数.txt
- c语言把mysql数据库语句和变量封装为一个语句
- C标准库中的函数定义在哪里?
- Dojo:不能在AccordionContainer.js中读取未定义的属性“h”。
- Crypto.js:在IE 11中未定义“Uint8ClampedArray”