Mysql 存储过程小例子
创建存储过程:
DELIMITER $$ USE `database_name`$$ DROP PROCEDURE IF EXISTS `add_or_update_user`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `add_or_update_user`(IN `id` INT, IN `username` VARCHAR(50)) BEGIN INSERT INTO USER(`id`,`username`,`created`) VALUES(id,username,UNIX_TIMESTAMP(NOW())) ON DUPLICATE KEY UPDATE id=VALUES(id), username=VALUES(username), created=VALUES(created); SELECT * FROM USER WHERE id=id; END$$ DELIMITER ;
调用存储过程:
CALL `add_or_update_user`(1, "username");