728x90
반응형
USE `classicmodels`;
DROP procedure IF EXISTS `get_order_by_cust`;
DELIMITER $$
USE `classicmodels`$$
CREATE PROCEDURE `get_order_by_cust` (
IN cust_no INT, # CustomerNumber를 IN으로 받고 OUT매개변수 각각 출력
OUT shipped INT,
OUT canceled INT,
OUT resolved INT,
OUT disputed INT)
BEGIN
SELECT count(*) INTO shipped
FROM orders
WHERE customerNumber = cust_no AND status = 'Shipped';
SELECT count(*) INTO canceled
FROM orders
WHERE customerNumber = cust_no AND status = 'Canceled';
SELECT count(*) INTO resolved
FROM orders
WHERE customerNumber = cust_no AND status = 'Resolved';
SELECT count(*) INTO disputed
FROM orders
WHERE customerNumber = cust_no AND status = 'Disputed';
END$$
DELIMITER ;
CALL get_order_by_cust(486,@shipped,@canceled,@resolved,@disputed);
SELECT @shipped,@canceled,@resolved,@disputed;
참고 및 출처 : blog.duveen.me/15?category=657591
728x90
반응형
'Data > MySQL' 카테고리의 다른 글
[MySQL] Stored Procedure 반복문 - WHILE / REPEAT / LOOP (0) | 2021.01.08 |
---|---|
[MySQL] Stored Procedure의 조건문 IF ELSEIF / CASE (0) | 2021.01.08 |
[MySQL] 저장 프로시저의 매개변수 - IN, OUT, INOUT (0) | 2021.01.07 |
[MySQL] Stored Procedure의 변수 (0) | 2021.01.07 |
[MySQL] 스토어드 프로시저(Stored Procedure) 사용법 (0) | 2021.01.07 |