MySQL 视图 存储过程(未完)
时间:2021-08-09
本文章向大家介绍MySQL 视图 存储过程(未完),主要包括MySQL 视图 存储过程(未完)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
视图概述 视图(View)是一种虚拟存在的表。视图并不在数据库中实际存在,行和列数据来自定义视图的查询中使用的表, 并且是在使用视图时动态生成的。通俗的讲,视图就是一条SELECT语句执行后返回的结果集。所以我们在创建视 图的时候,主要的工作就落在创建这条SQL查询语句上。 select * from city c, country t where c.country_id = t.country_id; select c.*,t.country_name from city c, country t where c.country_id = t.country_id; create view view_name as select语句; create view view_city_country as select c.*,t.country_name from city c, country t where c.country_id = t.country_id; select * from view_city_country; update view_city_country set city_name = '重庆市' where city_id = 1; //不建议更新视图; select * from view_city_country; alter view ivew_name as select语句; show tables; show table status\G show create table table_name; show create view view_name; show create view view_city_country; drop view view_name; drop view if exists view_city_country; drop index idx_city_name on city; 存储过程和函数 存储过程和函数是 事先经过编译并存储在数据库中的一段 SQL 语句的集合,调用存储过程和函数可以简化应用开 发人员的很多工作,减少数据在数据库和应用服务器之间的传输,对于提高数据处理的效率是有好处的。 存储过程和函数的区别在于函数必须有返回值,而存储过程没有。 函数 : 是一个有返回值的过程 ; 过程 : 是一个没有返回值的函数 ; 存储过程: create procedure procedure_name begin --SQL语句 end ; create procedure pro_test1() begin select 'Hello World' end ; delimiter $ //声明 结束符为 $符号了 调用存储过程: call procedure_name(); call pro_test1(); 查看存储过程 -- 查询db_name数据库中的所有的存储过程 select name from mysql.proc where db='db_name'; select name from mysql.proc where db='demo_01'; -- 查询存储过程的状态信息 show procedure status; -- 查询某个存储过程的定义 show create procedure test.pro_test1 \G; show create procedure pro_test1 \G; 删除 存储过程 drop procedure procedure_name; drop procedure pro_test1; select name from mysql.proc where db='demo_01'; 存储过程的语法: 存储过程是可以编程的,意味着可以使用变量,表达式,控制结构 , 来完成比较复杂的功能。 1)变量 declare: declare var_name type default create procedure pro_test1() begin declare num int default 10; select concat('num的值为:', num); end; call pro_test1(); set命令赋值, select...into...赋值操作: create procedure pro_test2() begin declare num int default 0; set num = num + 10; select num; end; call pro_test2; create procedure pro_test3() begin declare num int; select count(*) into num from city; select concat('city表中的记录数为:', num); end; call pro_test3; 2)if 条件判断 create procedure pro_test4() begin declare height int default 175; declare description varchar(50) default ''; if height >= 180 then set description='身材高挑'; elseif height >= 170 and height < 180 then set description='标准身材'; else set description='一般身材'; end if; select concat('身高',height,'对应的身材类型为:', description); end; call pro_test4; 3)传递参数 IN : 该参数可以作为输入,也就是需要调用方传入值 , 默认 OUT: 该参数作为输出,也就是该参数可以作为返回值 INOUT: 既可以作为输入参数,也可以作为输出参数 create procedure procedure_name([in/out/inout] 参数名 参数类型) ... IN 参数: create procedure pro_test5( in height int) begin declare description varchar(50) default ''; if height >= 180 then set description='身材高挑'; elseif height >= 170 and height < 180 then set description='标准身材'; else set description='一般身材'; end if; select concat('身高',height,'对应的身材类型为:', description); end; call pro_test5(190); OUT 参数: create procedure pro_test6( in height int,out description varchar(100)) begin if height >= 180 then set description='身材高挑'; elseif height >= 170 and height < 180 then set description='标准身材'; else set description='一般身材'; end if; end; call pro_test6(190);
原文地址:https://www.cnblogs.com/walkersss/p/15119895.html
- Redis 在Centos Linux 上的启动脚本
- 理解JavaScript的临时包装对象
- JavaScript实现私有属性
- 使用LRU算法缓存图片,android 3.0
- 深入理解JavaScript原型:prototype,__proto__和constructor
- Comparable 与 Comparator 浅析
- 必应首页平铺背景图片的实现方案
- 我们是如何优化HAProxy以让其支持200万个并发SSL连接的?
- 【译】《Understanding ECMAScript6》- 第八章-Module
- 【译】《Understanding ECMAScript6》- 第七章-Promise
- 自定义gradview
- Redis 起步
- JVM参数详解及OOM
- 【译】《Understanding ECMAScript6》- 第五章-Class
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- three.js 欧拉角和四元数
- three.js 制作逻辑转体游戏(上)
- three.js 制作魔方
- 安卓日常开发和逆向中常用的shell命令与非shell命令
- 使用python生成Latex公式语法
- 设计模式~桥梁模式
- 设计模式~模板方法模式
- three.js 郭先生制作太阳系
- 视频监控系统视频上云解决方案EasyCVR集成海康EHome私有协议系列——设备录像回看说明
- 视频监控系统视频上云解决方案EasyCVR集成海康EHome私有协议系列——报警模块说明
- three.js 制作一个三维的推箱子游戏
- IP摄像头RTSP协议网页无插件直播视频平台EasyNVR如何在直播或录像中添加定制化音频?
- three.js之初探骨骼动画
- three.js 自制骨骼动画(一)
- vue 人脸识别 demo