MySQL存储过程(带输入参数)实例
Posted sysadmin001
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL存储过程(带输入参数)实例相关的知识,希望对你有一定的参考价值。
DROP TABLE IF EXISTS `CUSTOMERS`; CREATE TABLE CUSTOMERS ( `id` INT ( 11 ) NOT NULL AUTO_INCREMENT,-- ID `cust_num` INT ( 11 ),-- 客户编号 `company` VARCHAR ( 20 ),-- 公司名称 `cust_rep` INT ( 11 ),-- 雇员 `credit_limit` DECIMAL ( 16, 2 ),-- 信用限额 PRIMARY KEY ( `id` ) ); DROP TABLE IF EXISTS `SALESREPS`; CREATE TABLE `SALESREPS` ( `id` INT ( 11 ) NOT NULL AUTO_INCREMENT,-- ID `quota` DECIMAL ( 16, 2 ),-- 销售目标 `empl_num` INT ( 11 ), PRIMARY KEY ( `id` ) ); INSERT INTO `SALESREPS` ( ID, QUOTA, EMPL_NUM ) VALUES ( 1, 20000.00, 103 ); DROP TABLE IF EXISTS `OFFICES`; CREATE TABLE `OFFICES` ( `id` INT ( 11 ) NOT NULL AUTO_INCREMENT, `target` DECIMAL ( 16, 2 ), `city` VARCHAR ( 20 ), PRIMARY KEY ( `id` ) ); INSERT INTO `OFFICES` ( id, target, city ) VALUES ( 1, 20000.00, ‘深圳‘ ); DROP PROCEDURE IF EXISTS `ADD_CUST`; DELIMITER // CREATE PROCEDURE `ADD_CUST` ( IN c_name VARCHAR ( 20 ), IN c_num INTEGER, IN cred_lim DECIMAL ( 16, 2 ), IN tgt_sls DECIMAL ( 16, 2 ), IN c_rep INTEGER, IN c_offc VARCHAR ( 20 ) ) BEGIN INSERT INTO customers ( cust_num, company, cust_rep, credit_limit ) VALUES ( c_num, c_name, c_rep, cred_lim ); UPDATE salesreps SET quota = quota + quota + tgt_sls WHERE empl_num = c_rep; UPDATE offices SET target = target + tgt_sls WHERE city = c_offc; COMMIT; END // CALL `ADD_CUST` ( ‘李四‘, 504, 200.00, 500.00, 309, ‘广州‘ );
以上是关于MySQL存储过程(带输入参数)实例的主要内容,如果未能解决你的问题,请参考以下文章