<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>archive</title><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/</link><description>Recent content on archive</description><generator>Hugo</generator><language>zh-CN</language><atom:link href="https://archive-w.netlify.app/doc/framework/mysql/lesson/index.xml" rel="self" type="application/rss+xml"/><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/01_database_related_concepts/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/01_database_related_concepts/</guid><description>&lt;h2 id="数据库相关概念">
 数据库相关概念
 &lt;a class="anchor" href="#%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9b%b8%e5%85%b3%e6%a6%82%e5%bf%b5">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>
&lt;h3 id="ddldata-definition-language">
 DDL(Data Definition Language)
 &lt;a class="anchor" href="#ddldata-definition-language">#&lt;/a>
&lt;/h3>
&lt;p class="warn">数据库定义语言 statements are used to define the database structure or schema. DDL是SQL语言的四大功能之一。用于定义数据库的三级结构，包括外模式、概念模式、内模式及其相互之间的映像，定义数据的完整性、安全控制等约束DDL不需要commit. CREATE、ALTER、DROP、TRUNCATE、COMMENT、RENAME。&lt;/p>
&lt;/li>
&lt;li>
&lt;h3 id="dmldata-manipulation-language">
 DML(Data Manipulation Language)
 &lt;a class="anchor" href="#dmldata-manipulation-language">#&lt;/a>
&lt;/h3>
&lt;p class="warn">数据操纵语言statements are used for managing data within schema objects. 由DBMS提供，用于让用户或程序员使用，实现对数据库中数据的操作。DML分成交互型DML和嵌入型DML两类。依据语言的级别，DML又可分成过程性DML和非过程性DML两种。 需要commit. INSERT、UPDATE、DELETE、MERGE、CALL、EXPLAIN PLAN、LOCK TABLE。&lt;/p>
&lt;/li>
&lt;li>
&lt;h3 id="dqldata-query-language">
 DQL(Data Query Language)
 &lt;a class="anchor" href="#dqldata-query-language">#&lt;/a>
&lt;/h3>
&lt;p class="warn">数据查询语言 SELECT、&lt;/p>
&lt;/li>
&lt;li>
&lt;h3 id="dcldata-control-language">
 DCL(Data Control Language)
 &lt;a class="anchor" href="#dcldata-control-language">#&lt;/a>
&lt;/h3>
&lt;p class="warn">数据库控制语言 授权，角色控制等。GRANT 授权、REVOKE 取消授权&lt;/p>
&lt;/li>
&lt;li>
&lt;h3 id="tcltransaction-control-language">
 TCL(Transaction Control Language)
 &lt;a class="anchor" href="#tcltransaction-control-language">#&lt;/a>
&lt;/h3>
&lt;p class="warn">事务控制语言。SAVEPOINT 设置保存点、ROLLBACK 回滚、SET TRANSACTION&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="reference">
 Reference
 &lt;a class="anchor" href="#reference">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>


 &lt;a href="https://www.cnblogs.com/henryhappier/archive/2010/07/05/1771295.html" rel="noopener" target="_blank">https://www.cnblogs.com/henryhappier/archive/2010/07/05/1771295.html&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/02_function/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/02_function/</guid><description>&lt;h2 id="函数">
 函数
 &lt;a class="anchor" href="#%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h2>
&lt;p class="warn">For server side help, type &amp;lsquo;help contents&amp;rsquo;&lt;/p>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="shell" data-line="" class="language-shell line-numbers" style="max-height: none">&lt;code class="language-shell">mysql&amp;gt; help contents
You asked for help about help category: &amp;quot;Contents&amp;quot;
For more information, type 'help &amp;lt;item&amp;gt;', where &amp;lt;item&amp;gt; is one of the following
categories:
 Account Management
 Administration
 Compound Statements
 Contents
 Data Definition
 Data Manipulation
 Data Types
 Functions
 Geographic Features
 Help Metadata
 Language Structure
 Plugins
 Procedures
 Storage Engines
 Table Maintenance
 Transactions
 User-Defined Functions
 Utility
&lt;/code>&lt;/pre>&lt;/div>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="shell" data-line="" class="language-shell line-numbers" style="max-height: none">&lt;code class="language-shell">mysql&amp;gt; help Functions
You asked for help about help category: &amp;quot;Functions&amp;quot;
For more information, type 'help &amp;lt;item&amp;gt;', where &amp;lt;item&amp;gt; is one of the following
categories:
 Bit Functions
 Comparison Operators
 Control Flow Functions
 Date and Time Functions
 Encryption Functions
 GROUP BY Functions and Modifiers
 Information Functions
 Locking Functions
 Logical Operators
 Miscellaneous Functions
 Numeric Functions
 Spatial Functions
 String Functions
&lt;/code>&lt;/pre>&lt;/div>
&lt;ul>
&lt;li>
&lt;h3 id="常见函数">
 常见函数
 &lt;a class="anchor" href="#%e5%b8%b8%e8%a7%81%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="单行函数">
 单行函数
 &lt;a class="anchor" href="#%e5%8d%95%e8%a1%8c%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="字符函数">
 字符函数
 &lt;a class="anchor" href="#%e5%ad%97%e7%ac%a6%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="数学函数">
 数学函数
 &lt;a class="anchor" href="#%e6%95%b0%e5%ad%a6%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="日期函数">
 日期函数
 &lt;a class="anchor" href="#%e6%97%a5%e6%9c%9f%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="其他函数">
 其他函数
 &lt;a class="anchor" href="#%e5%85%b6%e4%bb%96%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;/ul>
&lt;h2 id="reference">
 Reference
 &lt;a class="anchor" href="#reference">#&lt;/a>
&lt;/h2></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/03_dql/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/03_dql/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="dql语言的学习">
 DQL语言的学习
 &lt;a class="anchor" href="#dql%e8%af%ad%e8%a8%80%e7%9a%84%e5%ad%a6%e4%b9%a0">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>
&lt;h3 id="1基础查询">
 1.基础查询
 &lt;a class="anchor" href="#1%e5%9f%ba%e7%a1%80%e6%9f%a5%e8%af%a2">#&lt;/a>
&lt;/h3>
&lt;p class="warn">
语法：&lt;code>select 查询列表 from 表名;&lt;/code>
&lt;br>&lt;br>特点：
&lt;br>1，查询列表可以是：&lt;span style='color: blue'>表中的字段，常量值，表达式，函数&lt;/span>
&lt;br>2，查询的结果是一个虚拟的表格
&lt;br>&lt;br>1.查询表中的单个字段
&lt;br>&lt;code>select last_name from employees limit 10;&lt;/code>
&lt;br>&lt;br>2.查询表中的多个字段
&lt;br>&lt;code>select last_name, salary, email from employees limit 10;&lt;/code>
&lt;br>&lt;br>3.查询表中的所有字段
&lt;br>&lt;code>select * from employees limit 10;&lt;/code>
&lt;br>&lt;br>4.查询常量值
&lt;br>&lt;code>select 100;&lt;/code>,&lt;code>select 'john';&lt;/code>
&lt;br>&lt;br>5.查询表达式
&lt;br>&lt;code>select 100%98;&lt;/code>
&lt;br>&lt;br>6.查询函数
&lt;br>&lt;code>select version();&lt;/code>
&lt;br>&lt;br>7.起别名
&lt;br>① 便于理解，② 如果查询字段有重名，使用别名可以区分开来，③ 别名中有特殊字符使用引号扩起来
&lt;br>&lt;code>select 100%98 as 结果;&lt;/code>
&lt;br>&lt;code>select last_name as 姓,first_name as 名 from employees limit 10;&lt;/code>
&lt;br>&lt;br>8.去重
&lt;br># case: 查询员工表中涉及到的所有的部门编号
&lt;br>&lt;code>select distinct department_id from employees;&lt;/code>
&lt;br>&lt;br>9.+号的作用 ① 仅仅只有一个功能，运算符
&lt;br>&lt;code>select 100 + 90;&lt;/code> 连个操作数都为数值型，则做加法运算
&lt;br>&lt;code>select '123' + 90;&lt;/code> 213 其中一个为字符型，可以转换，做加法运算
&lt;br>&lt;code>select 'john' + 90&lt;/code> 90 转换失败，则将字符型数值转换成 0 再做加法。
&lt;br>&lt;code>select null + 10;&lt;/code> NULL 只要有一方为NULL, 则结果肯定为NULL。
&lt;br>所以下面字符串连接得使用&lt;code>concat函数&lt;/code>
&lt;br>case: 查询员工名和姓连接成一个字段，并显示为姓名
&lt;br>&lt;code>select concat(last_name,first_name) as 姓名 from employees limit 10;&lt;/code>&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/04_dml/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/04_dml/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="dml语言的学习">
 DML语言的学习
 &lt;a class="anchor" href="#dml%e8%af%ad%e8%a8%80%e7%9a%84%e5%ad%a6%e4%b9%a0">#&lt;/a>
&lt;/h2>
&lt;/li>
&lt;/ul></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/05_ddl/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/05_ddl/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="ddl语言的学习">
 DDL语言的学习
 &lt;a class="anchor" href="#ddl%e8%af%ad%e8%a8%80%e7%9a%84%e5%ad%a6%e4%b9%a0">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>
&lt;h3 id="1库和表的管理">
 1.库和表的管理
 &lt;a class="anchor" href="#1%e5%ba%93%e5%92%8c%e8%a1%a8%e7%9a%84%e7%ae%a1%e7%90%86">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="2常见数据类型介绍">
 2.常见数据类型介绍
 &lt;a class="anchor" href="#2%e5%b8%b8%e8%a7%81%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e4%bb%8b%e7%bb%8d">#&lt;/a>
&lt;/h3>
&lt;/li>
&lt;li>
&lt;h3 id="3常见约束">
 3.常见约束
 &lt;a class="anchor" href="#3%e5%b8%b8%e8%a7%81%e7%ba%a6%e6%9d%9f">#&lt;/a>
&lt;/h3>
&lt;p class="warn"> 含义：一种限制，用于限制表中的数据，为了保证表中数据的准确和可靠性
&lt;br>&lt;br> 分类：六大约束：
&lt;br>&lt;code>①:&lt;/code> NOT NULL： 非空，用于保证该字段的值不能为空。
&lt;br>&lt;code>②:&lt;/code> DEFAULT：默认，用于保证该字段有默认值。
&lt;br>&lt;code>③:&lt;/code> PRIMARY KEY： 主键，用于保证该字段的值具有唯一性，并且非空。
&lt;br>&lt;code>④:&lt;/code> UNIQUE：唯一，用于保证该字段的值具有唯一性，可以为空。
&lt;br>&lt;code>⑤:&lt;/code> CHECK：检查约束【mysql中不支持】
&lt;br>&lt;code>⑥:&lt;/code> FOREIGN KEY：外键，用于限制两个表的关系，用于保证该字段的值必须来自于主表的关联列的值。在从表中添加外键约束，用于引用主表中的某列的值。
&lt;br>&lt;br>添加约束的时机：
&lt;br>&lt;code>a).&lt;/code> 创建表时：
&lt;br>&lt;code>b).&lt;/code> 修改表时：
&lt;br>&lt;br>约束的添加分类：
&lt;br>&lt;code>1).&lt;/code> 列级约束：六大约束语法上都支持，但是外键约束没有效果
&lt;br>&lt;code>2).&lt;/code> 表级约束：除了非空，默认，其他都支持
&lt;br>&lt;span style='color: blue'>通用写法： 其他列级，外键表级&lt;/span>&lt;/p>
&lt;h6 id="测试约束用到的数据库">
 测试约束用到的数据库
 &lt;a class="anchor" href="#%e6%b5%8b%e8%af%95%e7%ba%a6%e6%9d%9f%e7%94%a8%e5%88%b0%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93">#&lt;/a>
&lt;/h6>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql">drop database students;
create database students character set utf8;
use students;

-- 创建外键引用的主表
drop table if exists major;
create table major(
 id int primary key,
 majorName varchar(20)
);
insert into major values (1, 'java'),(2, 'h5');
select * from major;
&lt;/code>&lt;/pre>&lt;/div>
&lt;ul>
&lt;li>
&lt;h4 id="创建表时添加约束">
 创建表时添加约束
 &lt;a class="anchor" href="#%e5%88%9b%e5%bb%ba%e8%a1%a8%e6%97%b6%e6%b7%bb%e5%8a%a0%e7%ba%a6%e6%9d%9f">#&lt;/a>
&lt;/h4> &lt;div class="docsify-example-panels"> &lt;div class="docsify-example-panel left-panel"style="max-width: 50%; width: 50%;">
&lt;h5 id="添加列级约束">
 添加列级约束
 &lt;a class="anchor" href="#%e6%b7%bb%e5%8a%a0%e5%88%97%e7%ba%a7%e7%ba%a6%e6%9d%9f">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql"># 1.1 添加列级约束
drop table if exists stu_info;
create table stu_info(
 id int primary key, # 主键
 stuName varchar(20) not null, # 非空
 gender char(1) check ( gender = '男' or gender = '女'), # 检查
 seat int unique, # 唯一
 age int default 18, # 默认
 majorId int references major(id) # 外键(列级没效果)
);
desc stu_info;
show index from stu_info;
insert into stu_info values (1,'john', '男', null, 19, 1);
insert into stu_info values (2,'lily', '男', null, 19, 2);
select * from stu_info;
&lt;/code>&lt;/pre>&lt;/div>&lt;/div>
 &lt;div class="docsify-example-panel right-panel"style="max-width: 50%; width: 50%;">
&lt;h5 id="添加表级约束">
 添加表级约束
 &lt;a class="anchor" href="#%e6%b7%bb%e5%8a%a0%e8%a1%a8%e7%ba%a7%e7%ba%a6%e6%9d%9f">#&lt;/a>
&lt;/h5>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql"># 1.2添加表级约束
drop table if exists stu_info;
create table stu_info(
 id int,
 stuName varchar(20) not null,
 gender char(1),
 seat int,
 age int default 18,
 majorId int,

 constraint pk primary key(id), # 主键
 constraint uq unique (seat), # 唯一
 constraint ck check ( gender = '男' or gender = '女' ), # 检查
 constraint fk_stu_info_major foreign key (majorId) references major(id) # 外键
);
&lt;/code>&lt;/pre>&lt;/div>&lt;/div>&lt;/div>

 &lt;hr/>
&lt;h6 id="主键和唯一对比">
 主键和唯一对比
 &lt;a class="anchor" href="#%e4%b8%bb%e9%94%ae%e5%92%8c%e5%94%af%e4%b8%80%e5%af%b9%e6%af%94">#&lt;/a>
&lt;/h6>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th align="center">&lt;/th>
&lt;th align="center">保证唯一性&lt;/th>
&lt;th align="center">是否允许为空&lt;/th>
&lt;th align="center">一个表中可以有多个&lt;/th>
&lt;th align="center">是否允许组合（联合）&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td align="center">主键&lt;/td>
&lt;td align="center">✅&lt;/td>
&lt;td align="center">❌&lt;/td>
&lt;td align="center">至多有1个主键&lt;/td>
&lt;td align="center">✅ &lt;br>【primary key(id,name)】&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td align="center">唯一&lt;/td>
&lt;td align="center">✅&lt;/td>
&lt;td align="center">✅ &lt;br>(可以有多个NULL)&lt;/td>
&lt;td align="center">可以有多个唯一字段&lt;/td>
&lt;td align="center">✅ &lt;br>【unique(seat, seat2】&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h6 id="外键的特点">
 外键的特点
 &lt;a class="anchor" href="#%e5%a4%96%e9%94%ae%e7%9a%84%e7%89%b9%e7%82%b9">#&lt;/a>
&lt;/h6>
&lt;div class="alert callout note">&lt;p class="title">&lt;span class="icon icon-note">&lt;/span> Note &lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/06_tcl/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/06_tcl/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="introtcl">
 Intro(TCL)
 &lt;a class="anchor" href="#introtcl">#&lt;/a>
&lt;/h2>
&lt;/li>
&lt;li>
&lt;h2 id="reference">
 Reference
 &lt;a class="anchor" href="#reference">#&lt;/a>
&lt;/h2>
&lt;ul>
&lt;li>


 &lt;a href="https://www.bilibili.com/video/BV12b411K7Zu?p=146&amp;vd_source=550a4dc4b2a914c0681a14307bbe8cbe" rel="noopener" target="_blank">delete 和 truncate在事务中的区别&lt;/a>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/07_view/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/07_view/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="introview">
 Intro(VIEW)
 &lt;a class="anchor" href="#introview">#&lt;/a>
&lt;/h2>
&lt;p class="warn"> 含义：虚拟表，和普通表一样使用
&lt;br>&lt;span style='color:blue'>mysql5.1版本出现的新特性是通过表动态生成的数据，行和列的数据来自定义视图的查询中使用的表，并且实在使用视图时动态生成的，只保存了sql逻辑，不保存查询结果&lt;/span>
&lt;br>&lt;br>好处：
&lt;br>&lt;code>1).&lt;/code>: 重用sql语句
&lt;br>&lt;code>2).&lt;/code>: 简化复杂的sql操作，不必知道它的查询细节
&lt;br>&lt;code>3).&lt;/code>: 保护数据，提高安全性
&lt;br>&lt;br>应用场景：
&lt;br>&lt;code>1).&lt;/code>: 多个地方用到了同样的查询结果
&lt;br>&lt;code>2).&lt;/code>: 该查询结果使用的sql语句较复杂&lt;/p>
&lt;ul>
&lt;li>
&lt;h3 id="示例">
 示例
 &lt;a class="anchor" href="#%e7%a4%ba%e4%be%8b">#&lt;/a>
&lt;/h3>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql">create view my_v1
as 
select stuname, majorname from stu_info s inner join major m on s.majorId = m.id;
&lt;/code>&lt;/pre>&lt;/div>
&lt;/li>
&lt;/ul>
&lt;p class="warn">case1: 查询姓张的学生名和专业名
&lt;br>&lt;code>select stuname,majorname from stu_info s inner join major m on s.majorId = m.id where s.stuname like '张%';&lt;/code>
&lt;br>&lt;code>create view v1 as select stuname, majorname from stu_info s inner join major m on s.majorId = m.id;&lt;/code>
&lt;br>&lt;code>select * from v1 where stuname like '张%';&lt;/code>&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/08_variables/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/08_variables/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="introvariables">
 Intro(VARIABLES)
 &lt;a class="anchor" href="#introvariables">#&lt;/a>
&lt;/h2>
&lt;p class="warn"> 变量分类：
&lt;br>【系统变量 [全局变量 | 会话变量] 】
&lt;br>【用户自定义变量 [用户变量 | 局部变量]】：&lt;/p>
&lt;ul>
&lt;li>
&lt;h3 id="系统变量">
 系统变量
 &lt;a class="anchor" href="#%e7%b3%bb%e7%bb%9f%e5%8f%98%e9%87%8f">#&lt;/a>
&lt;/h3>
&lt;p class="warn"> 说明：
&lt;br>变量由系统提供的，不是用户定义的，属于服务器层面
&lt;br>&lt;br>使用语法：
&lt;br>case1：查看所有的系统变量: &lt;code>&amp;lt;br&amp;gt;`show global|session variables;` &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;case2：查看满足条件的部分系统变量:&lt;/code>
&lt;br>&lt;code>show global|session variables like '%char%';&lt;/code>
&lt;br>&lt;br>case3：查看指定的某个系统变量的值: ``
&lt;br>&lt;code>select @@global|session.变量名;&lt;/code>
&lt;br>&lt;br>case4：为某个变量赋值:
&lt;br>&lt;code>set global|session 系统变量名 = 值;&lt;/code>
&lt;br>&lt;code>set @@global|session .系统变量名 = 值;&lt;/code>&lt;/p>
&lt;div class="alert callout attention">&lt;p class="title">&lt;span class="icon icon icon-attention">&lt;/span> Caution &lt;/p>&lt;p> 如果是全局级别，则需要加global，如果是会话级别，则需要加session，如果不写，则默认session&lt;/p>
&lt;/p>&lt;/div>
&lt;ul>
&lt;li>
&lt;h4 id="全局变量">
 全局变量
 &lt;a class="anchor" href="#%e5%85%a8%e5%b1%80%e5%8f%98%e9%87%8f">#&lt;/a>
&lt;/h4>
&lt;div class="alert callout note">&lt;p class="title">&lt;span class="icon icon-note">&lt;/span> Note &lt;/p>&lt;p> 作用域：服务器每次启动将会为所有的全局变量赋初始值，针对于所有的会话（连接）有效，但不能跨重启。&lt;span style='color: blue'>可通过配置文件进行重启生效&lt;/span>
&lt;br>&lt;br>使用语法：
&lt;br>case1：查看所有的系统变量:
&lt;br>&lt;code>show global variables;&lt;/code>
&lt;br>&lt;br>case2：查看满足条件的部分系统变量:
&lt;br>&lt;code>show global variables like '%char%';&lt;/code>
&lt;br>&lt;br>case3：查看指定的某个系统变量的值:
&lt;br>&lt;code>select @@global.autocommit;&lt;/code>
&lt;br>&lt;del>&lt;code>select @@tx_isolation;&lt;/code>&lt;/del>
&lt;br>&lt;br>case4：为某个变量赋值:
&lt;br>&lt;code>set global autocommit = 1;&lt;/code>，&lt;code>set @@global.autocommit = 0;&lt;/code>&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/09_procedure_function/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/09_procedure_function/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="introprocedure">
 Intro(PROCEDURE)
 &lt;a class="anchor" href="#introprocedure">#&lt;/a>
&lt;/h2>
&lt;p class="tip">类似于java中的方法，MySQL 5.0 版本开始支持存储过程。
&lt;br>含义：一组预先编译好的sql语句的集合，理解成批处理语句。
&lt;br>&lt;br>好处：
&lt;br>&lt;code>1).&lt;/code> 提高代码的重用性
&lt;br>&lt;code>2).&lt;/code> 简化操作
&lt;br>&lt;code>3).&lt;/code> 减少编译次数并且减少了和数据库服务器的连接次数，提高了效率。&lt;/p>
&lt;ul>
&lt;li>
&lt;h3 id="创建语法">
 创建语法
 &lt;a class="anchor" href="#%e5%88%9b%e5%bb%ba%e8%af%ad%e6%b3%95">#&lt;/a>
&lt;/h3>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql">create procedure 存储过程名称(参数列表)
begin
 存储过程题（一组合法的sql语句）
end
&lt;/code>&lt;/pre>&lt;/div>
&lt;div class="alert callout note">&lt;p class="title">&lt;span class="icon icon-note">&lt;/span> Note &lt;/p>&lt;p> 注意：
&lt;br>&lt;code>1).&lt;/code> 参数列表包含三部分（参数模式，参数名，参数类型），例如：&lt;code>IN stuname varchar(20)&lt;/code>
&lt;br>参数模式：
&lt;br>in: 该参数可以作为输入，也就是该参数需要调用方传入值
&lt;br>out: 该参数可以作为输出，也就是该参数可以作为返回值
&lt;br>inout: 该参数既可以作为输入又可以作为输出，也就是该参数既需要传入值，又可以返回值
&lt;br>&lt;br>&lt;code>2).&lt;/code> 如果存储过程体仅仅只有一句话，&lt;code>begin end&lt;/code>可以省略,存储过程体中的每条sql语句的结尾要求必须加分号。存储过程的结尾可以使用 &lt;code>delimiter&lt;/code>重新设置。语法：&lt;code>delimiter 结束标记&lt;/code>
&lt;br>&lt;code>delimiter $&lt;/code>&lt;/p>
&lt;/p>&lt;/div>
&lt;/li>
&lt;li>
&lt;h3 id="调用语法">
 调用语法
 &lt;a class="anchor" href="#%e8%b0%83%e7%94%a8%e8%af%ad%e6%b3%95">#&lt;/a>
&lt;/h3>
&lt;p>&lt;code>call 存储过程(实参列表);&lt;/code>&lt;/p>
&lt;ul>
&lt;li>
&lt;h4 id="1空参列表">
 1.空参列表
 &lt;a class="anchor" href="#1%e7%a9%ba%e5%8f%82%e5%88%97%e8%a1%a8">#&lt;/a>
&lt;/h4>
&lt;p class="warn"> case1：插入到admin表中五条记录
&lt;br>使用下面代码创建存储过程，
&lt;br>然后使用语句&lt;code>call myp1();&lt;/code>进行调用&lt;/p>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql">delimiter $
create procedure myp1()
begin
 insert into admin(username, `password`) values('john1', '0000'), ('lily', '0000'), ('rose', '0000'), ('jack', '0000'), ('tom', '0000');
end $
&lt;/code>&lt;/pre>&lt;/div>
&lt;/li>
&lt;li>
&lt;h4 id="2in模式列表">
 2.(IN)模式列表
 &lt;a class="anchor" href="#2in%e6%a8%a1%e5%bc%8f%e5%88%97%e8%a1%a8">#&lt;/a>
&lt;/h4>
&lt;p class="warn">case1：创建存储过程实现 根据女神名，查询对应的男神信息
&lt;br>使用下面代码创建存储过程，
&lt;br>然后使用语句&lt;code>call myp2('小昭');&lt;/code>进行调用，控制台会展示返回值。&lt;/p></description></item><item><title/><link>https://archive-w.netlify.app/doc/framework/mysql/lesson/10_flow_control/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://archive-w.netlify.app/doc/framework/mysql/lesson/10_flow_control/</guid><description>&lt;ul>
&lt;li>
&lt;h2 id="introflow-control">
 Intro(FLOW CONTROL)
 &lt;a class="anchor" href="#introflow-control">#&lt;/a>
&lt;/h2>
&lt;p class="tip"> 简单介绍：
&lt;br>顺序结构：程序从上至下依次执行
&lt;br>分支结构：程序从两条或多条路径中选择一条去执行
&lt;br>循环结构：程序在满足一定条件的基础上，重复执行一段代码&lt;/p>
&lt;ul>
&lt;li>
&lt;h3 id="分支结构">
 分支结构
 &lt;a class="anchor" href="#%e5%88%86%e6%94%af%e7%bb%93%e6%9e%84">#&lt;/a>
&lt;/h3>
&lt;ul>
&lt;li>
&lt;h4 id="if函数">
 IF函数
 &lt;a class="anchor" href="#if%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h4>
&lt;p class="warn"> 功能：实现简单的双分支
&lt;br>&lt;br>语法：&lt;code>if(表达式1，返回值2，返回值3)&lt;/code>
&lt;br>如果表达式1成立，则if使用返回值2，否则使用返回值3.
&lt;br>&lt;br>应用：任何地方&lt;/p>
&lt;/li>
&lt;li>
&lt;h4 id="case函数">
 CASE函数
 &lt;a class="anchor" href="#case%e5%87%bd%e6%95%b0">#&lt;/a>
&lt;/h4> &lt;div class="docsify-example-panels">&lt;p class="warn">特点：
&lt;br>&lt;code>1).&lt;/code> 可以作为表达式，嵌套在其他语句中使用，可以放在任何地方，begin end 中或begin end外面。可以作为单独的语句去使用，只能放在 begin end 中。
&lt;br>&lt;code>2).&lt;/code> 如果when中的值满足或条件成立，则执行对应的then后面的语句，并且结束case，如果都不满足，则执行else中的语句或值
&lt;br>&lt;code>3).&lt;/code> else可以省略，如果else省略了，并且所有when条件都不满足，则返回NULL。&lt;/p>
 &lt;div class="docsify-example-panel left-panel"style="max-width: 50%; width: 50%;">
&lt;div class="alert callout note">&lt;p class="title">&lt;span class="icon icon-note">&lt;/span> Note &lt;/p>&lt;p> 情况一：类似于java中的switch语句，一般用作实现等值判断&lt;/p>
&lt;/p>&lt;/div>
&lt;div class="outer yosemite">&lt;div class="dot red">&lt;/div>&lt;div class="dot amber">&lt;/div>&lt;div class="dot green">&lt;/div>&lt;/div>
&lt;div class="code-toolbar">&lt;pre data-lang="sql" data-line="" class="language-sql line-numbers" style="max-height: none">&lt;code class="language-sql">case 变量|表达式|字段
when 要判断的值 then 返回的值1或语句1;
when 要判断的值 then 返回的值1或语句1;
...
else 返回的值n或语句n;
end case;
&lt;/code>&lt;/pre>&lt;/div>&lt;/div>
 &lt;div class="docsify-example-panel right-panel"style="max-width: 50%; width: 50%;">
&lt;div class="alert callout note">&lt;p class="title">&lt;span class="icon icon-note">&lt;/span> Note &lt;/p></description></item></channel></rss>