mysql自定义函数实现查询主键并自增长


 structure for currval
-- ----------------------------
DROP FUNCTION IF EXISTS `currval`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `currval`(seq_name VARCHAR(50)) RETURNS int(11)
BEGIN
    DECLARE
        current INTEGER;


SET current = 0;

SELECT
    currentValue INTO current
FROM
    t_sequence
WHERE
    seqname = seq_name;

RETURN current;

END
;;
DELIMITER ;

-- ----------------------------
-- Function structure for nextval
-- ----------------------------
DROP FUNCTION IF EXISTS `nextval`;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `nextval`(seq_name VARCHAR(50)) RETURNS varchar(50) CHARSET utf8
BEGIN  
   DECLARE currentval INTEGER;
   select currentValue INTO currentval from t_sequence where seqname=seq_name;
   IF currentval >= 99999999 THEN 
     UPDATE t_lincomb_sequence  
     SET currentValue = 0 
     WHERE seqname = seq_name;
   ELSE 
     UPDATE t_sequence  
     SET currentValue = currentValue + increment  
     WHERE seqname = seq_name;
   END IF;
   RETURN CONCAT(date_format(SYSDATE(),'%Y%m%d%H%i%S'),LPAD(currval(seq_name),8,'0'));  
END
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `t_pro_product_push_status`;
DELIMITER ;;
CREATE TRIGGER `t_pro_product_push_status` AFTER UPDATE ON `t_pro_product` FOR EACH ROW BEGIN
	UPDATE t_tss_push SET `status`=1,`push_num`=0
	WHERE `business_id` = NEW.store_id;
END
;;
DELIMITER ;

 

你可能感兴趣的:(java)