본문 바로가기
Develop/DB

MySQL 밀리초까지 구하는 함수

by bellsilver7 2020. 3. 1.
728x90
DELIMITER $$

DROP FUNCTION IF EXISTS DB_NAME.string_print$$

CREATE FUNCTION DB_NAME.string_print( copy_str VARCHAR(30) ) RETURNS VARCHAR(30)
BEGIN

SELECT 
CONCAT( 
  DATE_FORMAT(SYSDATE(), '%Y-%m-%d %H:%i:%s.'), 
  RIGHT(
    CONV( 
      CONCAT(
        SUBSTRING(uid,16,3), 
        SUBSTRING(uid,10,4), 
        SUBSTRING(uid,1,8)
      )
      ,16
      ,10
    ) DIV 10000 - (141427 * 24 * 60 * 60 * 1000)
    ,3
  ) 
) AS current_mills 
INTO copy_str
FROM (SELECT UUID() uid) AS alias;

RETURN copy_str;

END $$
  
DELIMITER ;

SELECT DB_NAME.string_print(0) AS regist;

 

728x90

댓글