简体   繁体   English

MySQL 存储过程关于调用

[英]MySQL stored procedure regarding a call

I am new in programming and this is my first question in the forum.我是编程新手,这是我在论坛上的第一个问题。 Can you explain me please in this code in MySQL why I get the result 3?您能否在 MySQL 的这段代码中解释一下为什么我得到结果 3? I thought I would get 2. If I run again it increases every time by one.我以为我会得到 2。如果我再次跑步,它每次都会增加 1。 Thank you.谢谢你。

DELIMITER $$
CREATE PROCEDURE uservariable()
BEGIN
SET @x = @x + 1;
SELECT @x;
END$$

SET @x = 1;
CALL uservariable();
CALL uservariable();

SET @x = @x + 1;

This line increments @x value by one each time uservariable() procedure is called.每次调用@x uservariable()过程时,此行都会将 @x 值加一。

SET @x = 1; --@x value is 1 
CALL uservariable(); --@x value is 2
CALL uservariable(); --@x value is 3

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

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