当前位置:网站首页>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)
边栏推荐
- Timed thread pool implements request merging
- YOLO物体识别,生成数据用到的工具
- TD联合Modelsim进行功能仿真
- 自定義Redis連接池
- Hystrix implements request consolidation
- MySQL default transaction isolation level and row lock
- tinyxml2 读取和修改文件
- 上班第一天的报错(Nessus安装winpcap报错)
- Required request body is missing:(跨域问题)
- How to use PHP spoole to implement millisecond scheduled tasks
猜你喜欢
上班第一天的报错(AWVS卸载不彻底)
BugkuCTF-web24(解题思路及步骤)
Web security and defense
Mysql默认事务隔离级别及行锁
BugkuCTF-web21(详细解题思路及步骤)
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd
QT QLabel样式设置
Read 30 minutes before going to bed every day_ day4_ Files
How to use pyqt5 to make a sensitive word detection tool
Image recognition - data augmentation
随机推荐
2837xd 代码生成——StateFlow(4)
How to use PHP spoole to implement millisecond scheduled tasks
Binary and decimal system of C language
YOLO物体识别,生成数据用到的工具
自定義Redis連接池
图像识别-数据采集
每天睡觉前30分钟阅读_day3_Files
Mysql默认事务隔离级别及行锁
Int to string, int to qstring
Mathematics in machine learning -- point estimation (I): basic knowledge
2837xd code generation - stateflow (3)
2837xd code generation - Summary
Typora安装包分享
web安全与防御
Bugkuctf-web21 (detailed problem solving ideas and steps)
TD conducts functional simulation with Modelsim
2837xd code generation - Supplement (2)
C语言之判断直角三角形
Break the cocoon | one article explains what is the real cloud primordial
2837xd 代碼生成——補充(1)