Mysqlmysql学习笔记(进阶一)### 会话变量与全局变量 各客户端的session互不干扰 查看全部会话变量 show session variables; 查看单条 show session variables like 'auto%'; 更改会话变量 set 变量名 = '值' set @@session.变量名='值' 全局变量 全部 show global variables;作者王明昌发布时间2018-08-19最后更新2018-08-19文章目录存储过程函数的创建视图 ### 会话变量与全局变量 各客户端的session互不干扰 查看全部会话变量 show session variables; 查看单条 show session variables like 'auto%'; 更改会话变量 set 变量名 = '值' set @@session.变量名='值' 全局变量 全部 show global variables; 单条 show global variables like 'auto%' 更改 set global 变量名 = '值' set @@global.变量名='值' ### 存储过程 步骤: 1. 选择一个数据库 2. 改变分隔符(结束符) :delimiter $$; 3. 创建存储过程 create procedure p_hello() begin select "hello"; select "ddd"; end $$; 4. 执行存储过程 恢复结束符 delimiter ; 执行 call p_hello; 局部变量 定义:declare 变量名 数据类型 default 默认值 三参数: in输入参数 out输出参数 inout输入输出参数 复制----declare--- begin declare inta int; set inta = 88; select inta; end ----in----- create procedure p_hello(in p_int int) begin set p_int = p_int+1; select p_int; end $$; delimiter ; set @p_int = 3; call p_hello(@p_int) //@p_int 的值在存储外并不会改变; ----out--- create procedure p_hello(out p_int int) begin set p_int = p_int+1; select p_int; end $$; delimiter ; set @p_int = 3; call p_hello(@p_int) //进入时所赋的值并不生效,不认可,为null //@p_int 的值在存储外会改变; ----inout--- create procedure p_hello(inout p_int int) begin set p_int = p_int+1; select p_int; end $$; delimiter ; set @p_int = 3; call p_hello(@p_int) //进入的值被认可 //@p_int 的值在存储外不会会改变; ### 流程控制语句 选择语句 if else 复制begin ----- if age >=18 then select '成年人'; else select '未成年人'; end if ----- if age >=18 then select '成年人'; elseif age>=60 then select '未成年人'; else select '未成年人'; end if ----- end $$; case select id,name,(case gender when '1' then '男' else '女' end) from user; select ifnull(null,'不是空值') from uu; ifnull(exp1,exp2)//exp1如果为null,返回exp2的值 复制begin declare aaa int; case v_empno when 1 then set aaa ='我是1'; when 2 then set aaa = '我是2'; when 3 then set aaa = '我是3'; else set aaa = 'null'; end case; end; $$; 循环语句 while 复制begin declare i int default 1; declare result int default 0; while i<=100 do set result = result+i; set i=i+1; end while; repeat 复制repeat 内容 until 条件 //退出循环的条件 end repeat; ------------- begin declare imin int default 1; declare imax int default 1; seelct max(a) into imax from user; seelct min(a) into imin from user; repeat if imin % 2 = 0 then update....... endif; set imin = imin+1; until imin>imax (没有分号) endrepeat; end; loop 复制loop名字:loop 内容 if 条件 then leave loop名字 endif; end loop; 复制myloop:loop if imax %2=1 then ipdate........ end if; set imax = imax+1 if imin > imax then leave loop myloop;//离开循环 end if; end loop; 定义条件和处理 定义条件(在begin中定义) declare continue handler for sqlstate '错误代码值' set 变量=变量值 复制存储过程中,前一句sql出错,不影响下一条 存储过程 删除存储过程 drop procedure if exists 存储过程名称  函数的创建  视图
2017-12-04案例-多表查询、子查询实例(有答案)1.创建student和score表 CREATE TABLE student ( id INT(10) NOT NULL UNIQUE PRIMARY KEY , name VARCHAR(20)
2017-12-10案例-多表查询、子查询实例03(有答案)一、设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2
2017-12-06案例-多表查询、子查询实例02(有答案)以下所有操作在查询管理器中手工书写sql语句完成 1、按下列步骤创建数据库和表 1.2、在这个数据库中创建一个名为[学生表]的表,由[学号]、[姓名]、[专业]、[班级] 字段组成。[学号] 字段为主
2018-01-18mysql数据表同时使用创建时间/更新时间字段原因:一张表同时只能使用一个current_timestamp 创表 1. 用createtime记录创建时间 2. 用updatetime记录更新时间 create table test1(a va
2018-07-09MySQL 中TEXT的使用TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB LONGTEXT 4,294,967,295
2018-12-11mysql错误 | Error writing file‘frm‘(Errcode: 28)Error writing file‘frm‘(Errcode: 28) 磁盘空间不足引起的,删除一些没用的东西吧