mysql自定义函数

 
SET GLOBAL log_bin_trust_function_creators = 1;

##############to_date
DELIMITER $$
DROP FUNCTION IF EXISTS `to_date`$$
CREATE FUNCTION `to_date`(s CHAR(255),s2 CHAR(255)) RETURNS CHAR(255) CHARSET utf8
BEGIN   
 RETURN s;
END$$
DELIMITER ;

############# to_char
DELIMITER $$
DROP FUNCTION IF EXISTS `to_char`$$
CREATE FUNCTION `to_char`(s CHAR(255),s2 CHAR(255)) RETURNS CHAR(255) CHARSET utf8
BEGIN   
 IF s2 = 'yyyy-MM-dd' THEN
  return DATE_FORMAT(s,'%Y-%m-%d');
 END IF;

 RETURN s;
END$$
DELIMITER ;

############ myencrypt_str
DELIMITER $$
DROP FUNCTION IF EXISTS `myencrypt_str`$$
CREATE FUNCTION `myencrypt_str`(s CHAR(255)) RETURNS CHAR(255) CHARSET utf8
BEGIN   
 RETURN HEX(des_encrypt(s)); 
END$$
DELIMITER ;

############ mydecrypt_str
DELIMITER $$
DROP FUNCTION IF EXISTS `mydecrypt_str`$$
CREATE FUNCTION `mydecrypt_str`(s CHAR(255)) RETURNS CHAR(255) CHARSET utf8
BEGIN   
 RETURN des_decrypt(unhex(s)); 
END$$
DELIMITER ;
############# nvl
DELIMITER $$
DROP FUNCTION IF EXISTS `nvl`$$
CREATE FUNCTION `nvl`(s CHAR(255)) RETURNS CHAR(255) CHARSET utf8
BEGIN   
 RETURN IFNULL(s,0); 
END$$
DELIMITER ;

你可能感兴趣的:(mysql,Date,function,hex)