存储过程-入门案例
作者:互联网
一、数据准备
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for users -- ---------------------------- DROP TABLE IF EXISTS `users`; CREATE TABLE `users` ( `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键', `user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户名', `sex` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '性别', PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; SET FOREIGN_KEY_CHECKS = 1; INSERT INTO `users`(`id`, `user_name`, `sex`) VALUES (1, '张学友', '男'); INSERT INTO `users`(`id`, `user_name`, `sex`) VALUES (2, '迪丽热巴', '女'); INSERT INTO `users`(`id`, `user_name`, `sex`) VALUES (3, '周杰伦', '男'); INSERT INTO `users`(`id`, `user_name`, `sex`) VALUES (4, '杨幂', '女');
二、格式
delimiter 自定义结束符号 create procedure 存储名([in,out,inout]参数名数据类型...) begin sql语句 end 自定义结束符号 delimiter ;
三、案例
DROP PROCEDURE IF EXISTS proc1; delimiter $$ create procedure proc1() begin SELECT * from users; end $$ delimiter ; call proc1();
标签:存储,SET,入门,utf8mb4,name,案例,user,id,users 来源: https://www.cnblogs.com/sportsky/p/16311432.html