문제

I am a novice programmer and I'm currently working with functions and stored procedures in MySQL using Workbench 5.6 . I've been searching for some time now here on SO and on the Web for a formal definition of the "@" operator in MySQL and it's proper use, but I wasn't able to find some concrete explanation.

Let's say that I have this :

 /*..... Stored Procedure... */

 declare i int ;
 set @i = 1 ;
 select @i ;

 /* do some other stuff */
 End; 

The result of select will be 1 ,instead, if I do:

 select i ;

I will get a Null result. From my intuition so far, I think that is accessing the direction in the memory of a stored variable and prints/modifies its content,still I'm not quite sure.Could you shed some more light? Are there any other uses of it?

Thanks a priori.

도움이 되었습니까?

해결책

It isn't an operator (I suspect you come from PHP, where it is an operator). It's the syntax for user-defined variables:

User variables are written as @var_name, where the variable name var_name consists of alphanumeric characters, “.”, “_”, and “$”. A user variable name can contain other characters if you quote it as a string or identifier (for example, @'my-var', @"my-var", or @my-var).

다른 팁

The @ denotes a variable, you prefix your variables with the @ to prevent confusing them with column names and other schema, it also makes life a lot easier when looking at code. When you enter select I from x;, your looking for column I, which doesn't exist in the table, hence the null.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top