当前位置:网站首页>High level application of SQL statements in MySQL database (II)
High level application of SQL statements in MySQL database (II)
2022-07-02 09:45:00 【Guyu Taoist priest】
Table of Contents
- 1、CREATE VIEW View
- 2.UNION combine
- 3. Intersection value
- 4. No intersection value
- 5.CASE
- 3、 ... and 、 Regular expressions
- Four 、 stored procedure
- 1. summary
- 2. Advantages of stored procedures
- 3. Create stored procedure
- 4. Calling stored procedure
- 5. View stored procedures
- 6. Parameters of stored procedure
- 7. Delete stored procedure
1、CREATE VIEW View
View : Can be treated as a virtual table or stored query .
The difference between a view and a table is , There are actually stored data in the table , And a view is a structure built on a table , It doesn't actually store data itself .
The temporary table disappears automatically after the user exits or disconnects from the database , The view does not .
Views don't contain data , Just store its definition , Its purpose is to simplify complex queries . For example, you need to connect and query several tables , But also to carry out statistical sorting and other operations , Write SQL Statements can be cumbersome , Connect several tables with a view , Then query the view , Just like querying a table , Very convenient .
grammar :CREATE VIEW View table name AS SELECT sentence ;
example :
2.UNION combine
Put two SQL The results of the statement are combined , Two SQL The fields generated by the statement need to be the same data type
UNION: There will be no duplicate data values for the generated results , And sort according to the order of the fields
3. Intersection value
Take two. SQL The intersection of statement results
example :
4. No intersection value
Show the first SQL Result of statement , And with the second SQL Statement has no result of intersection , It can't be repeated
example :
5.CASE
yes SQL Used as a IF-THEN-ELSE And so on
usage :
3、 ... and 、 Regular expressions
The specific application is shown in the following table :
Matching mode | describe | example |
---|---|---|
^ | Match the start character of the text | ‘^bd’ Match with bd Starting string |
$ | Match the end character of the text | ‘qn$’ Match with qn a null-terminated string |
. | Match any single character | ‘s.t’ Match any s and t A string with one character between |
***** | Match zero or more characters before it | ‘fo*t’ matching t There is any one in front o |
+ | Match preceding characters 1 Times or times | ‘hom+’ Match with ho start , At least one back m String |
character string | Match contains the specified string | ‘clo’ The match contains clo String |
[…] | Match any character in the character set | ‘[abc]’ matching a perhaps b perhaps c |
[^…] | Match any characters that are not in brackets | ‘[^ab]’ Match does not contain a perhaps b String |
{n} | Match the previous string n Time | ‘g{2}’ The match contains 2 individual g String |
{n,m} | Match the previous string at least n Time , at most m Time | ‘f{1,3}’ matching f least 1 Time , most 3 Time |
p1 | p2 | matching p1 or p2 |
usage :
Four 、 stored procedure
1. summary
A stored procedure is a set of functions to accomplish SQL Statement set
And I learned before Shell The function is almost , In essence, it is the reuse of code
Further details :
In the process of using stored procedures, common or complex work is used in advance SQL The statement is written and stored with a specified name
This process is compiled and optimized and stored in the database server
When you need to use this stored procedure , Just call it
Stored procedures perform better than traditional SQL Faster , More efficient execution
2. Advantages of stored procedures
After one execution , The generated binary code will reside in the buffer , Improve execution efficiency
SQL Statement plus a collection of control statements , High flexibility
Store on the server side , When called by the client , Reduce network load
Can be called repeatedly , Can be modified at any time , Does not affect client calls
Can complete all database operations , You can also control the information access rights of the database
3. Create stored procedure
4. Calling stored procedure
5. View stored procedures
usage :
6. Parameters of stored procedure
IN Input parameters : Indicates that the caller passes a value... To the procedure ( The incoming value can be literal or variable )
OUT Output parameters : Indicates that the procedure passes out a value to the caller ( Multiple values can be returned )( Outgoing values can only be variables )
INOUT Input/output parameter : It means that the caller passes in a value to the procedure , It also indicates that the procedure passes out a value to the caller ( Values can only be variables )
example :
7. Delete stored procedure
The method to modify the contents of stored procedures is to delete the original stored procedures , Then create a new stored procedure with the same name
usage :
8. Control statement of stored procedure
8.1 Conditional statements (if)
8.2 Loop statement (while)
边栏推荐
- What is the function of laravel facade
- 图像识别-数据采集
- BugkuCTF-web16(备份是个好习惯)
- Alibaba /热门json解析开源项目 fastjson2
- tinyxml2 读取和修改文件
- Mysql 多列IN操作
- Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
- C language programming problems
- Hystrix implements request consolidation
- JDBC回顾
猜你喜欢
Off grid control of three-phase inverter - PR control
Mysql 多列IN操作
Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
tinyxml2 读取和修改文件
三相逆变器离网控制——PR控制
Pool de connexion redis personnalisé
Idea view bytecode configuration
逆变器simulink模型——处理器在环测试(PIL)
Image recognition - data augmentation
随机推荐
Bold prediction: it will become the core player of 5g
Customize redis connection pool
Safety production early warning system software - Download safety production app software
互联网API接口幂等设计
攻防世界-Web进阶区-unserialize3
How to install PHP in CentOS
因上努力,果上随缘
Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
2837xd code generation - Supplement (3)
Off grid control of three-phase inverter - PR control
JDBC review
分享一篇博客(水一篇博客)
Required request body is missing:(跨域问题)
cmake的命令-官方文档
TD联合Modelsim进行功能仿真
2837xd Code Generation - Supplement (1)
每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
三相逆变器离网控制——PR控制
Mysql默认事务隔离级别及行锁
上班第一天的报错(Nessus安装winpcap报错)