【发布时间】:2021-05-02 23:09:39
【问题描述】:
我曾尝试在变量或参数之前添加或删除“@”,但没有任何反应。
查询
start transaction;
set @recordClient = (select ClientId from by_test_db1.recordcd where SN = 'abc' );
set @logClient = (select ClientId from by_test_db1.log where SN = 'abc' );
select concat(@recordClient,@logClient);
commit;
SP
delimiter $$
create procedure TEST(newSN varchar(50))
begin
start transaction;
set @recordClient = (select ClientId from by_test_db1.recordcd where SN = newSN );
set @logClient = (select ClientId from by_test_db1.log where SN = newSN );
select concat(@recordClient,@logClient);
commit;
end $$
delimiter ;
call TEST('abc');
MySQL 版本 5.7
recordcd表中有1亿行,QUERY运行得又快又好,但是SP 运行太慢以至于超时并报错
错误代码:2013。在查询期间丢失与 MySQL 服务器的连接
我尝试了很多方法,但都没有奏效,我不知道为什么会出现如此荒谬的情况,我什至不知道如何寻找这种情况的答案。
【问题讨论】:
-
我既不明白您为什么要进行事务处理,也不了解为什么要使用存储过程。标准连接查询有什么问题?
标签: mysql stored-procedures transactions