mysql教程 MySqlDump数据库教程备份代码
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `UF_Get_tMaxCode`(
V_iType INT
) RETURNS varchar(10) CHARSET utf8
BEGIN
/*
业务描述:根据编码类别产生编码输入参数:
V_iType:编码类别,定义建tMaxCode的iType字段的定义调用示例:
SELECT UF_Get_tMaxCode(1);创建日期:
创建人:*/
DECLARE iCode INT;IF V_iType IN (1,3)
THEN
#非订单类
IF EXISTS (SELECT dtLast FROM tMaxCode WHERE iType=V_iType LIMIT 0,1)
THEN
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
SET iCode=1;
END IF;
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
#订单类
IF EXISTS (SELECT iMax FROM tMaxCode WHERE iType=V_iType AND DATEDIFF(dtLast,CURRENT_DATE)=0 LIMIT 0,1)
THEN
#上次生成时间是当天
SELECT IFNULL(iMax,0)+1 INTO iCode FROM tMaxCode WHERE iType=V_iType;
ELSE
SET iCode=1;
END IF;
END IF;
1 2