在检查别人的把sqlserver里的存储过程转移到mysql里的配置文件发现sqlserver里有比如DECLARE @id CHAR(64);SELECT @id=$t(roles,id) FROM $t(roles)...
到了mysql就没了declare,直接是SELECT $t(roles,id) INTO @id FROM $t(roles)...想问下,按mysql的标准规范,这个是加上好还是可以不加上呢?

解决方案 »

  1.   

    如果是 @x 变量,是SESSOIN级以上的变量,不需要 declare
    如果是变量,比如 x,则必须 declare
    建议参考一下MYSQL手册中的介绍,估计5分钟就可阅读完毕。 MYSQL官方有免费的中文手册。12.8.3.1. DECLARE for Local Variables
    DECLARE var_name [, var_name] ... type [DEFAULT value]This statement is used to declare local variables within stored programs. To provide a default value for the variable, include a DEFAULT clause. The value can be specified as an expression; it need not be a constant. If the DEFAULT clause is missing, the initial value is NULL. Local variables are treated like stored routine parameters with respect to data type and overflow checking. See Section 12.1.12, “CREATE PROCEDURE and CREATE FUNCTION Syntax”. Local variable names are not case sensitive. The scope of a local variable is within the BEGIN ... END block where it is declared. The variable can be referred to in blocks nested within the declaring block, except those blocks that declare a variable with the same name.