MySQL一个简单的存储过程demo
使用的工具是Navicat for MySQL。
首先创建一个学生表
mysql> create table student(s_name varchar(20) not null default '不详',sex varchar(4) not null default '不详',s_no int(5) auto_increment,age int(3) not null,height int(3) not null,primary key(s_no));
Query OK, 0 rows affected mysql> insert into student (s_name,sex,age,height) values('小张','男',21,176);
Query OK, 1 row affected mysql> insert into student (s_name,sex,age,height) values('小李','男',22,175);
Query OK, 1 row affected mysql> insert into student (s_name,sex,age,height) values('小明','男',25,178);
Query OK, 1 row affected mysql> insert into student (s_name,sex,age,height) values('小红','女',23,165);
Query OK, 1 row affected mysql> insert into student (s_name,sex,age,height) values('小丽','女',19,160);
Query OK, 1 row affected mysql> select * from student;
+--------+-----+------+-----+--------+
| s_name | sex | s_no | age | height |
+--------+-----+------+-----+--------+
| 小张 | 男 | 1 | 21 | 176 |
| 小李 | 男 | 2 | 22 | 175 |
| 小明 | 男 | 3 | 25 | 178 |
| 小红 | 女 | 4 | 23 | 165 |
| 小丽 | 女 | 5 | 19 | 160 |
+--------+-----+------+-----+--------+
5 rows in set
然后写一个存储过程,传入姓名s_name,返回学号s_no
delimiter $$
drop procedure if exists pro_gets_no;
create procedure pro_gets_no(in pname varchar(20),out pno int(5))
begin
select s_no into pno from student where s_name=pname;
end $$
delimiter;
运行之后调用
set @pname='小红';
set @pno=0;
call pro_gets_no(@pname,@pno);
select * from student where s_no=@pno;
结果如下
再创建一个存储过程,将传入姓名的学生身高height修改为175,并且将之后的姓名改为身高姓名作为姓名输出
delimiter $$
drop procedure if exists pro_updateHeight;
create procedure pro_updateHeight(inout pname varchar(20))
begin
update student set height=175 where s_name=pname;
select concat(height,s_name) into pname from student where s_name=pname;
end $$
delimiter;
运行之后调用
set @pname='小李';
call pro_updateHeight(@pname);
select @pname;
结果如下
MySQL一个简单的存储过程demo的更多相关文章
- C#中缓存的使用 ajax请求基于restFul的WebApi(post、get、delete、put) 让 .NET 更方便的导入导出 Excel .net core api +swagger(一个简单的入门demo 使用codefirst+mysql) C# 位运算详解 c# 交错数组 c# 数组协变 C# 添加Excel表单控件(Form Controls) C#串口通信程序
C#中缓存的使用 缓存的概念及优缺点在这里就不多做介绍,主要介绍一下使用的方法. 1.在ASP.NET中页面缓存的使用方法简单,只需要在aspx页的顶部加上一句声明即可: <%@ Outp ...
- mysql 如何创建一个简单的存储过程
1 用mysql客户端登入2 选择数据库 mysql>use test3 查询当前数据库有哪些存储过程 mysql>show procedure status where Db='test ...
- SQL点滴28—一个简单的存储过程
原文:SQL点滴28-一个简单的存储过程 在表中写入一条数据同事要向另外一个表中写入信息,所以会使用到事务.实际使用的时候还会一次向一个表中吸入多条数据,下面的存储过程,将字符串拆分成数组然后写入到表 ...
- .net core api +swagger(一个简单的入门demo 使用codefirst+mysql)
前言: 自从.net core问世之后,就一直想了解.但是由于比较懒惰只是断断续续了解一点.近段时间工作不是太忙碌,所以偷闲写下自己学习过程.慢慢了解.net core 等这些基础方面学会之后再用.n ...
- spring boot一个简单用户管理DEMO
概述 该Demo旨在部署一个简单spring boot工程,包含数据编辑和查看功能 POM配置 <?xml version="1.0" encoding="UTF- ...
- 实现一个简单的虚拟demo算法
假如现在你需要写一个像下面一样的表格的应用程序,这个表格可以根据不同的字段进行升序或者降序的展示. 这个应用程序看起来很简单,你可以想出好几种不同的方式来写.最容易想到的可能是,在你的 JavaScr ...
- 1020关于mysql一个简单语句的执行流程
MySQL的语句执行顺序 转自http://www.cnblogs.com/rollenholt/p/3776923.html MySQL的语句一共分为11步,如下图所标注的那样,最先执行的总是FRO ...
- (转)一个简单的rest_framework demo
转发:https://www.cnblogs.com/fu-yong/p/9100559.html models.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 from ...
- 一个简单的rest_framework demo
models.py from django.db import models class UserInfo(models.Model): username = models.CharField(max ...
随机推荐
- iOS 图片裁剪方法
iOS 图片裁剪方法 通过 CGImage 或 CIImage 裁剪 UIImage有cgImage和ciImage属性,分别可以获得CGImage和CIImage对象.CGImage和CIImage ...
- 【2017-02-26】String类、Math类、DateTime类
一.String类 黑色小扳手 - 属性 后面不带括号紫色立方体 - 方法 后面带括号 字符串.Length - 字符串长度,返回int类型 字符串.TrimStart() - 去 ...
- C#基础 运算符
运算符分为5类-- 1.算数运算符[加加(++) 减减(--) 加(+) 减(-) 乘(*) 除(/) 取余(%)] (1)前++和后++的区别 using System; using ...
- UVALive 7045 Last Defence
ProblemK. Last Defence Description Given two integersA and B. Sequence S is defined as follow: • S0 ...
- iOS 推送问题全解答《十万个为啥吖?》
Q 1:为啥收不到推送(1)? 如果收到推送时,App 在前台运行,那么: iOS 10 before 顶部横幅不会弹出.没有任何展示,你以为「没有收到推送」. iOS 10 after 如果没有实现 ...
- Java日常总结之LinkedList、ArrayList的效率分析
前言: 在我们平常开发中难免会用到List集合来存储数据,一般都会选择ArrayList和LinkedList,以前只是大致知道ArrayList查询效率高LinkedList插入删除效率高,今天来实 ...
- 最近新版本的pangolin出现了点问题,我把可用的旧版本上传到了github
经测试该版本编译没有问题. 下载地址:https://github.com/zzx2GH/Pangolin.git
- [LeetCode] Dp
Best Time to Buy and Sell Stock 题目: Say you have an array for which the ith element is the price of ...
- KoaHub平台基于Node.js开发的Koa JWT认证插件代码信息详情
koa-jwt Koa JWT authentication middleware. koa-jwt Koa middleware that validates JSON Web Tokens and ...
- CDbConnection failed to open the DB connection
打开数据库失败 有我遇到的有寄给问题: 1 Not find Drive 2 SQLSTATE[28000] [1045] Access denied for user 'xxx'@'localhos ...