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