当前位置:网站首页>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)

边栏推荐
- Idea view bytecode configuration
- 保存视频 opencv::VideoWriter
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
- Matlab生成dsp程序——官方例程学习(6)
- 2837xd code generation - stateflow (2)
- How to choose between efficiency and correctness of these three implementation methods of distributed locks?
- Operation and application of stack and queue
- Attributes of classfile
- Data insertion in C language
- Required request body is missing: (cross domain problem)
猜你喜欢

MySQL multi column in operation

Operation and application of stack and queue

MySQL default transaction isolation level and row lock

Insight into cloud native | microservices and microservice architecture

Vs+qt set application icon

图像识别-数据清洗

idea查看字节码配置

一次聊天勾起的回忆

PI control of grid connected inverter (grid connected mode)

2837xd code generation - stateflow (1)
随机推荐
Microservice practice | Eureka registration center and cluster construction
TD conducts functional simulation with Modelsim
C语言之到底是不是太胖了
图像识别-数据清洗
上班第一天的报错(AWVS卸载不彻底)
Image recognition - data augmentation
Off grid control of three-phase inverter - PR control
Bold prediction: it will become the core player of 5g
Customize redis connection pool
每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime
逆变器simulink模型——处理器在环测试(PIL)
Minimum number of C language
VIM operation command Encyclopedia
Creation and jump of activity
ZK configuration center -- configuration and use of config Toolkit
Typora installation package sharing
2837xd 代码生成——StateFlow(4)
Methods of classfile
In depth analysis of how the JVM executes Hello World
What are the differences between TP5 and laravel