码迷,mamicode.com
首页 > 数据库 > 详细

MySQL存储过程(带输入参数)实例

时间:2018-05-12 00:07:45      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:procedure   销售   客户   公司   入参   分享   add   color   char   

技术分享图片

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存储过程(带输入参数)实例

标签:procedure   销售   客户   公司   入参   分享   add   color   char   

原文地址:https://www.cnblogs.com/halo-halo/p/9026078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!