MySQL存儲過程單參數或多參數傳遞
阿新 • • 發佈:2018-10-04
pre 操作 ces pro varchar in out 開發 office code MySQL開發的存儲過程幾乎都需要參數。這些參數使存儲過程更加靈活和有用。 在MySQL中,參數有三種模式:IN,OUT或INOUT。
IN orderStatus VARCHAR(25),
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END$$
DELIMITER ; END$$
DELIMITER ;
1,單參數 in
DELIMITER $$
USE dc3688
$$
CREATE PROCEDURE GetOfficeByCountry(IN countryName VARCHAR(255))
BEGIN
SELECT *
FROM offices
WHERE country = countryName;
END$$
DELIMITER ;
2,多參數 (in out)
DELIMITER $$
CREATE PROCEDURE CountOrderByStatus(
OUT total INT)
BEGIN
SELECT count(orderNumber)
INTO total
FROM orders
WHERE status = orderStatus;
END$$
DELIMITER ;
調用方法
CALL CountOrderByStatus(‘Shipped‘,@total);
SELECT @total;
3,參數 inout
DELIMITER $$
CREATE PROCEDURE set_counter(INOUT count INT(4),IN inc INT(4))
BEGIN
SET count = count + inc;
DELIMITER ;
調用過程
SET @counter = 1;
CALL set_counter(@counter,1);
可以實際操作一下不同參數用法
文章來自 www.dc3688.com
MySQL存儲過程單參數或多參數傳遞