简体   繁体   English

mysql存储过程参数似乎不适用于“@”(在符号处)

[英]mysql stored procedure parameters don't seem to work with “@” (At sign)

I'm changing a MS SQL database over to MySQL. 我正在将MS SQL数据库更改为MySQL。

I've rewritten one of the stored procedures which takes a parameter called @Account_Number . 我重写了一个存储过程,它带有一个名为@Account_Number的参数。 When I run the stored procedure in MySQL I get the following Message: Error Code: 1048 Column 'Account_Number' cannot be null . 当我在MySQL中运行存储过程时,我收到以下消息: Error Code: 1048 Column 'Account_Number' cannot be null

Using the workbench I finally tinkered around and figured out that when I removed the "@" from my stored procedures and renamed them like parmAccount_Number the stored procedure would execute. 使用工作台我终于修改了一下,并发现当我从存储过程中删除“@”并将其重命名为parmAccount_Number ,存储过程将执行。

I really want to keep the stored procedure input parameters named the same, and I don't want to go back and rename my MS SQL parameters... just in case I want to flip flop Databases. 我真的想保持名为相同的存储过程输入参数,我不想返回并重命名我的MS SQL参数...以防万一我想翻转数据库。

I can't find any info on what MySQL does with the "@".... 我找不到MySQL用“@”做什么的任何信息....

Is there a way to make it work with "@" ? 有没有办法让它与“@”一起使用?

EDIT 编辑

Declaring the stored procedure 声明存储过程

CREATE PROCEDURE `My_sp`(
 `@Account_Number` varchar(8),....)

insert portion of sp 插入部分sp

insert into 
My_Table
(
    Account_Number, ...
)
values
(
    @Account_Number,...
)

No, you can't name MySQL procedure variables starting with the @ sign. 不,您不能以@符号开头命名MySQL过程变量。

The @ sign character signifies a MySQL User-Defined Variable, which is quite different than a procedure variable. @符号字符表示MySQL用户定义的变量,它与过程变量完全不同。

The big differences is that user defined variable aren't declared (they don't have a datatype), and they have scope within a session (database connection), not just a procedure. 最大的区别在于未声明用户定义的变量(它们没有数据类型),并且它们在会话(数据库连接)中具有范围,而不仅仅是过程。 It persists for the entire session. 它会持续整个会话。 (This also means it's subject to modification anywhere in the session, any SQL statement, trigger, function or procedure can modify it, which makes it very useful, and also makes it a potential pitfall. (这也意味着它可以在会话中的任何地方进行修改,任何SQL语句,触发器,函数或过程都可以对其进行修改,这使得它非常有用,并且还使其成为一个潜在的陷阱。

It's possible to use user defined variables as the actual values passed to a procedure or function. 可以使用用户定义的变量作为传递给过程或函数的实际值。 But you can't name MySQL procedure variables or parameters starting with an @ sign. 但是,您无法命名以@符号开头的MySQL过程变量或参数。

I believe this is compliant with the SQL 2003 standards. 我相信这符合SQL 2003标准。

Documentation here: 文档在这里:

http://dev.mysql.com/doc/refman/5.5/en/user-variables.html http://dev.mysql.com/doc/refman/5.5/en/user-variables.html

UPDATE UPDATE

Interesting. 有趣。

Given that you are able to get a procedure compiled by enclosing the parameter name in backticks (as shown in the example statement you added)... 假设你能够通过在反引号中包含参数名来获得编译的过程(如你添加的示例语句所示)......

You might try enclosing the parameter name reference in the INSERT statement in backticks as well. 您也可以尝试在反引号的INSERT语句中包含参数名称引用。 (I've never tested that; I've never tried "back ticking" variable names before; I've never seen that done before.) But if the procedure is actually compiling, then maybe that would work. (我从来没有测试过;我以前从未尝试过“回复”变量名称;我以前从未见过这样做过。)但是如果程序实际上正在编译,那么也许这样可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM