zoukankan      html  css  js  c++  java
  • 通过数据库 订单号递增

    函数的定义

    -- 订单号
    delimiter $$
    create function queryNo(pyear int) returns bigint(20)
    begin
    set @sum = 11;
    UPDATE shop_order_no set `value` = `value`+1 where year =pyear;
    set @sum = (SELECT value from shop_order_no where year = pyear limit 1);
    if (@sum is null) THEN
    INSERT INTO `shop_order_no `(year,value) VALUE (pyear, 1);
    set @sum = 1;
    end if ;
    return @sum;
    end;

    $$
    delimiter ;

    订单号增加表  一年一个开始

    DROP TABLE IF EXISTS `shop_order_no `;
    CREATE TABLE `shop_order_no ` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `year` int(10) NOT NULL,
    `value` bigint(20) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;

    -- ----------------------------
    -- Records of shop_order_no 
    -- ----------------------------
    INSERT INTO `shop_order_no ` VALUES ('1', '2019', '0');
    INSERT INTO `shop_order_no ` VALUES ('2', '2020', '0');
    INSERT INTO `shop_order_no ` VALUES ('3', '2021', '0');
    INSERT INTO `shop_order_no ` VALUES ('4', '2022', '0');
    INSERT INTO `shop_order_no ` VALUES ('5', '2023', '0');
    INSERT INTO `shop_order_no ` VALUES ('6', '2024', '0');
    INSERT INTO `shop_order_no ` VALUES ('7', '2025', '0');
    INSERT INTO `shop_order_no` VALUES ('8', '2026', '0');
    INSERT INTO `shop_order_no ` VALUES ('9', '2027', '0');

  • 相关阅读:
    nowcoderD Xieldy And His Password
    Codeforces681D Gifts by the List
    nowcoder80D applese的生日
    Codeforces961E Tufurama
    Codeforces957 Mahmoud and Ehab and yet another xor task
    nowcoder82E 无向图中的最短距离
    nowcoder82B 区间的连续段
    Codeforces903E Swapping Characters
    Codeforces614C Peter and Snow Blower
    Codeforces614D Skills
  • 原文地址:https://www.cnblogs.com/little-tech/p/11512123.html
Copyright © 2011-2022 走看看