雪花ID

DELIMITER $$

CREATE FUNCTION snowflake_id() RETURNS BIGINT

BEGIN

DECLARE snowflake BIGINT;

SET snowflake = ROUND(CONNECTION_ID() / 10000) 10000000000000000 + (UNIX_TIMESTAMP() 1000000) + MICROSECOND(SYSDATE(6) );

RETURN snowflake;

END$$

DELIMITER ;