먼저 저장 프로시저를 만들어 보겠습니다 -
mysql> DELIMITER // mysql> CREATE PROCEDURE ExtenddatesWithMonthdemo(IN date1 datetime, IN NumberOfMonth int ) -> BEGIN -> SELECT DATE_ADD(date1,INTERVAL NumberOfMonth MONTH) AS ExtendDate; -> END; -> // Query OK, 0 rows affected (0.20 sec) mysql> DELIMITER ;
이제 help SHOW CREATE 명령으로 저장 프로시저가 존재하는지 확인합니다.
쿼리는 다음과 같습니다 -
mysql> SHOW CREATE PROCEDURE ExtenddatesWithMonthdemo; The following is the output displaying the details of the stored procedure we created above: +--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+ | Procedure | sql_mode | Create Procedure | character_set_client | collation_connection | Database Collation | +--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+ | ExtenddatesWithMonthdemo | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | CREATE DEFINER = `root`@`%` PROCEDURE `ExtenddatesWithMonthdemo`(IN date1 datetime, IN NumberOfMonth int ) BEGIN SELECT DATE_ADD(date1,INTERVAL NumberOfMonth MONTH) AS ExtendDate; END | utf8 | utf8_general_ci | utf8_general_ci | +--------------------------+--------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+ 1 row in set (0.00 sec)
CALL 명령을 사용하여 저장 프로시저를 호출합니다. 쿼리는 다음과 같습니다 -
mysql> call ExtenddatesWithMonthdemo('2019-02-13',6);
출력
+---------------------+ | ExtendDate | +---------------------+ | 2019-08-13 00:00:00 | +---------------------+ 1 row in set (0.10 sec) Query OK, 0 rows affected (0.12 sec)