认识下mysql中的存储过程使用以及语法
来源:互联网 发布:怎么做淘宝宝贝详情页 编辑:程序博客网 时间:2024/05/29 10:12
存储过程:
简单介绍下,一般存储过程用于数据比较复杂以及业务复杂的情景,数据量比较大,对性能要求高的情况下;
存储过程是定义函数;
使用存储过程可以减少和脚本语言交互以及带宽,从而提高与数据库交互的效率;
语法以及使用例子:
create procedure p()
begin
sqlxxxxxxxxxxxxx
end;
声明变量 declare 变量名 变量类型 [默认值]
declare name varchar default ' ' ;
循环
while i<100 do
循环内容
end while
create procedure p2()
begin
declare total int default 0;
default num int default 0;
while num <=100 do
set total := total + num;
set num := num + 1;
end while;
select total;
end;
-------in out inout 输入输出类型
p8:
create procedure p8(in n int , out total int)
p7: ---输入的参数,一直加到输入的参数为止
create procedure p6(in n int) ---in输入的参数
begin
declare total int default 0;
declare num int default 0;
while num<n do
set num := num+1;
set total := total+num;
end while
select total;
end $
p8:
create procedure p8(in n int , out total int)
p9: ---inout
create procedure p9(input age int)
begin
set age := age + 20;
end$
-----此时需要在声明一个变量值
-----set @curage := 18;
#######case结构
create procedure p10()
begin
declare pos int default 0;
case pos
when 1 then select 'flying';
when 2 then select 'sea';
when 3 then select 'island';
end case;
end$
#####repeat 循环
语法格式:
repeat
sql statement
sql statement
until condition end repeat;
例子 :
create procedure p11()
begin
declare total default 0;
declare i default 0;
repeat
set i := i+1;
set total := total + 1;
end repeat
select total;
end$
- 认识下mysql中的存储过程使用以及语法
- mysql的存储过程使用和语法
- mysql存储过程语法
- MySQL存储过程语法
- mysql存储过程语法
- mysql存储过程语法
- MYSQL存储过程入门1、语法以及in,out区别
- mysql存储过程以及游标的使用
- MySQL存储过程的认识
- 学习SQLSERVER的存储过程-之一认识存储过程语法
- MySQL 存储过程中的游标使用
- MYsql 存储过程简单语法
- MYsql 存储过程简单语法
- 存储过程语法(MySQL)
- MySQL 存储过程 常用语法
- MYSQL 存储过程语法入门
- mysql存储过程语法学习
- MYSQL 存储过程语法入门
- 自动释放池的前世今生 ---- 深入解析 autoreleasepool
- qt超强精美绘图控件 - QCustomPlot一览 及 安装使用教程
- 科学论文2--Thoughts on high-performance computing的阅读与实践
- Codeforces Round #378 (Div. 2) C. Epidemic in Monstropolis(模拟)
- 关于qrencode的使用
- 认识下mysql中的存储过程使用以及语法
- 为您解惑:H5语义元素..........
- Markdown入门学习小结
- Js 实现字数限制,超出部分显示为省略号
- ELK 日志分析平台搭建
- 最大流 — Edmond Karp算法
- Unity有限状态机详解
- 我对Javascript数组的理解
- 使用QCustomPlot绘图的基础