当前位置:网站首页>MySQL Chapter 6 Summary
MySQL Chapter 6 Summary
2022-06-26 10:21:00 【m0_ sixty-one million nine hundred and sixty-one thousand eight】
Create stored procedure .
have access to CREATE PROCEDURE Statement to create a stored procedure , The syntax is as follows :
CREATE PROCEDURE < The process of > ( [ Process parameters [,…] ] ) < The process of body > [ Process parameters [,…] ] Format [ IN | OUT
| INOUT ] < Parameter name > < type >
The grammar is as follows :
The process of
The name of the stored procedure , By default, it is created in the current database . If you need to create stored procedures in a specific database , Add the name of the database before the name , namely db_name.sp_name.
It should be noted that , Names should be avoided as much as possible MySQL The same name as the built-in function , Otherwise, there will be mistakes .
2) Process parameters
Parameter list of stored procedure . among ,< Parameter name > For the parameter name ,< type > Is the type of parameter ( It can be anything that works MySQL data type ). When there are multiple parameters , The parameter list is separated from each other by commas . Stored procedures can have no parameters ( At this point, the name of the stored procedure still needs to be followed by a pair of parentheses ), There can be 1 Two or more parameters .
MySQL Stored procedures support three types of parameters , Input parameters 、 Output parameters and inputs / Output parameters , Use them separately IN、OUT and INOUT Three keywords identify . among , Input parameters can be passed to a stored procedure , The output parameter is used when the stored procedure needs to return an operation result , And input / The output parameter can act as either an input parameter or an output parameter .
It should be noted that , The name of the parameter should not be the same as the column name of the data table , Otherwise, although no error message will be returned , But the stored procedure SQL Statement will treat the parameter name as a column name , This leads to unpredictable results .
3) The process of body
The main part of the stored procedure , Also known as stored procedure body , Contains what must be executed when calling a procedure SQL sentence . This part is based on the keyword BEGIN Start , With keywords END end . If there is only one in the stored procedure body SQL sentence , You can omit BEGIN-END sign .
In the creation of stored procedures , A very important... Is often used MySQL command , namely DELIMITER command , Especially for operating through the command line MySQL Users of the database , It is more important to learn to use this command .
stay MySQL in , The server processes SQL By default, the statement ends with a semicolon . However , When the stored procedure is created , The stored procedure body may contain multiple SQL sentence , these SQL If the statement still ends with a semicolon , that MySQL When processing, the server will start with the first SQL The semicolon at the end of the statement is used as the terminator of the whole program , Instead of dealing with the following... In the stored procedure body SQL sentence , It's obviously not going to work .
To solve the above problems , Usually use DELIMITER Command changes the end command to another character . The syntax is as follows :
DELIMITER $$
The grammar is as follows :
$$ Is a user-defined Terminator , Usually this symbol can be some special symbols , Like two “?” Or two “¥” etc. .
When using DELIMITER On command , Backslashes should be avoided “\” character , Because it is MySQL The escape character of .
stay MySQL The command line client input is as follows SQL sentence .
mysql > DELIMITER ??
Successfully execute this SQL After the statement , Any order 、 The end flag of a statement or program is replaced by two question marks “??” 了 .
If you want to switch back to the default semicolon “;” As an end sign , It's in MySQL The command line client can enter the following statement :
mysql > DELIMITER ;
Be careful :DELIMITER And semicolon “;” There must be a space between . When the stored procedure is created , Must possess CREATE ROUTINE jurisdiction .
1, Create stored procedure
delimiter $
create procedure in_out_procedure(in procedure_id int,out count_number
int) begin select count(*) into count_number from temp_url where
id=procedure_id; end $ delimiter ;
Be careful :delimiter $ Change the separator ,MySQL In the database , Use delimiter Keyword to change the separator , When we are creating triggers or stored procedures , Often used .
2, Execute stored procedures :
call in_out_procedure(1,count_number); MySQL How to call a stored procedure with parameters ? call
in_out_procedure(1,@param1); select @param1;
Be careful , With output out Stored procedure , When we use , You need to get the output first , Here we use parameters param1, It is equivalent to receiving the returned result , Then you can use this return result .
Create a stored procedure that applies cursors
1、 What is a cursor ?
Cursors are like iterators or pointers , It points to the first record in the database , Every time a record is fetched, the cursor moves backward one bit
2、 Cursors 4 Parts of
1、declare Affirming – declare You name cursor for select statement
2、open open --open You name
3、fetch Value --fetch You name into var1,var2,[…]
4、close close –close You name
3、 Cursor to and select Statement with
declare c cursor for select * from user
This sentence means a cursor c Point to select * from user The first record in the query result set ( The record has not been taken from the database , Here you can write logic to decide whether to return the record to the caller , Every time you pick it up , The cursor moves back one bit )
Create and use transactions
A:atomicity Atomicity
C:Consistency Uniformity
I: Isolation Isolation,
D:durabiliity reliability
The basic way to write a transaction
View table engine commands
show engines;
innodb Support transactions ,myisam Unsupported transaction
The opening of business :
begin perhaps start transaction
..
边栏推荐
- Test instructions - common interface protocol analysis
- Cloud native essay using Hana expression database service on Google kubernetes cluster
- Crawler related articles collection: pyppeter, burpsuite
- MySQL第十次作业-视图
- Global and Chinese market of aluminum sunshade systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Renesas electronics launched a complete intelligent sensor solution for Internet of things applications
- Software testing - how to select the appropriate orthogonal table
- TensorFlow遇到的各种错误
- Nested recyclerview in nestedscrollview automatically slides to the bottom after switching
- Glide's most common instructions
猜你喜欢

3行3列整形二维数组,求对角之和

A list of common methods for customizing paint and canvas of view

Configuration internationale

Hcia-dhcp experiment

DBSCAN

The IE mode tab of Microsoft edge browser is stuck, which has been fixed by rolling back the update

字符串常量池、class常量池和运行时常量池

String constant pool, class constant pool, and runtime constant pool

定制拦截器

Day 3 array, pre post, character space, keyword and address pointer
随机推荐
瑞萨电子面向物联网应用推出完整的智能传感器解决方案
904. fruit baskets
全渠道、多场景、跨平台,App如何借助数据分析渠道流量
String constant pool, class constant pool, and runtime constant pool
首批12家企业入驻!广州首个集中展销老字号产品专柜开张
[untitled]
方法区里面有什么——class文件、class文件常量池、运行时常量池
When will JVM garbage collection enter the older generation
Some problems to be considered when designing technical implementation scheme
35 qlineedit control synthesis example
Introduction to libmagic
Yarn package management tool
Redis master-slave replication in win10 system
Threadmode interpretation of eventbus
druid数据源实现后台监控
Index summary of blog articles -- Industrial Internet
The basis of C language grammar -- factoring by function applet
What is LSP
Problems encountered in the application and development of Hongmeng and some roast
Win10安装tensorflow-quantum过程详解