MSSql:
create procedure Proc(@TableName varchar(50), @Identity int output)
as
begin
select @Identity=FNext from biIdentity where FTableName=@TableName update biIdentity set FNext=FNext+FStep where FTableName=@TableName
end转为MySql:
create procedure Proc(in TableName varchar(50),out Identity int)
BEGIN
select FNext into Identity from biIdentity where FTableName=TableName; update biIdentity set FNext=FNext+FStep where FTableName=TableName;
END;
转为MySql总是失败,我是这么调用的:
call Proc('biUser',@Id);
select @Id;结果总是返回null不知道是我调用错误,还是转为存储过程错误
create procedure Proc(@TableName varchar(50), @Identity int output)
as
begin
select @Identity=FNext from biIdentity where FTableName=@TableName update biIdentity set FNext=FNext+FStep where FTableName=@TableName
end转为MySql:
create procedure Proc(in TableName varchar(50),out Identity int)
BEGIN
select FNext into Identity from biIdentity where FTableName=TableName; update biIdentity set FNext=FNext+FStep where FTableName=TableName;
END;
转为MySql总是失败,我是这么调用的:
call Proc('biUser',@Id);
select @Id;结果总是返回null不知道是我调用错误,还是转为存储过程错误
检查一下你的表中是否有 FTableName='biUser' 这条记录!mysql> create table biIdentity(FNext int,FStep int,FTableName varchar(10));
Query OK, 0 rows affected (0.08 sec)mysql> insert into biIdentity values (1,1,'biUser');
Query OK, 1 row affected (0.05 sec)mysql> select * from biIdentity;
+-------+-------+------------+
| FNext | FStep | FTableName |
+-------+-------+------------+
| 1 | 1 | biUser |
+-------+-------+------------+
1 row in set (0.00 sec)mysql>
mysql> delimiter //
mysql> create procedure Proc(in TableName varchar(50),out Identity int)
-> BEGIN
-> select FNext into Identity from biIdentity where FTableName=TableName;
-> update biIdentity set FNext=FNext+FStep where FTableName=TableName;
-> END;
-> //
Query OK, 0 rows affected (0.00 sec)mysql> delimiter ;
mysql>
mysql> call Proc('biUser',@Id);
Query OK, 1 row affected (0.08 sec)mysql> select @Id;
+------+
| @Id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)mysql>
call Proc('biUser',@Id);
select @Id; 上面这两句是在 MySQL Query Browser 执行的,不知道我为什么总是返回null,在cmd就不会,第一次用MySql,不熟悉。
我先执行 call Proc('biUser',@Id);
然后再到 select @Id; 按ctrl + enter 执行