In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about the declare sentences in MySQL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
What are the uses of MySQLdeclare statements?
(1) ExamplewithtwoDECLAREstatements
Two instances of DECLARE statements
CREATEPROCEDUREp8 () BEGINDECLAREaINT;DECLAREbINT;SETa=5;SETb=5;INSERTINTOtVALUES (a); SELECTs1*aFROMtWHEREs1 > = bposition End.
The variables defined in the process are not really defined, you just define them in the BEGIN/END block. Note that these variables are different from session variables. You cannot use the modifier @ you must clearly declare variables and their types in the BEGIN/END block. Once a variable is declared, you can use it anywhere you can use session variables, text, and column names.
(2) ExamplewithnoDEFAULTclauseandSETstatement
No examples of default clauses and setting statements
CREATEPROCEDUREp9 () BEGINDECLAREaINT/*thereisnoDEFAULTclause*/;DECLAREbINT/*thereisnoDEFAULTclause*/;SETa=5;/*thereisaSETstatement*/SETb=5;/*thereisaSETstatement*/INSERTINTOtVALUES (a); SELECTs1*aFROMtWHEREs1 > = bposition End.
There are many ways to initialize variables. If there is no default clause, the initial value of the variable is NULL. You can use the set statement to assign values to variables at any time.
(3) ExamplewithDEFAULTclause
An example with a DEFAULT clause
CREATEPROCEDUREp10 () BEGINDECLAREa,bINTDEFAULT5;INSERTINTOtVALUES (a); SELECTs1*aFROMtWHEREs1 > = bposition / end /
We have made some changes here, but the result is still the same. Here the DEFAULT clause is used to set the initial value, so there is no need to separate the implementation of the DECLARE and SET statements.
What are the uses of MySQLdeclare statements?
(4) ExampleofCALL
An example of a call
Mysql > CALLp10 () / / +-+ | s1yoga | +-+ | 25 | 25 | +-+ 2rowsinset (0.00sec) QueryOK,0rowsaffected (0.00sec)
The results show that the process can work properly.
(5) Scope
Scope
CREATEPROCEDUREp11 () BEGINDECLAREx1CHAR (5) DEFAULT'outer';BEGINDECLAREx1CHAR (5) DEFAULT'inner';SELECTx1;END;SELECTx1;END;//
These are the declare statements in the MySQL shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 255
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.