Some instances understand the mysql database stored procedures and mysql database Stored Procedures

Source: Internet
Author: User

Some instances understand the mysql database stored procedures and mysql database Stored Procedures
Mysql stored procedure: encapsulate SQL:

Create procedure p1 () beginselect * from t_news; end $ // simple mysql Stored procedure instance
Display stored procedure information: \ G (horizontal table uses vertical table output)



Delimiter $ changes the execution symbol until mysql encounters the $ command to start executing the statement. set names solves the mysql garbled problem, but restores the mysql to the previous Character set status after it is restarted.
Call stored procedure name () call Stored Procedure
Parameters:
Create procedure p2 (n int) # beginselect * from t_category where cid> n; end $


Control Structure:
Create procedure p3 (n int, j char (1 )) # begin if j = 'H' then # different from other languages, the then symbol must be added. Note: = Not = select * from t_category where cid> n; elseselect * from t_category where cid <n; end if; end $


Calculate the sum of... n:
Create procedure p4 (n smallint) # include the parameter begin declare I int; declare s int; set s = 0; set I = 1; while I <= n doset s = s + I; set I = I + 1; end while; select s; end $


Differences between stored procedure and function: different names: stored procedure: procedure function no return value for Stored procedure

How does mysql use a stored procedure to create the same table for multiple databases?

Two key points:
First, whether your access user has the same permissions for this table. If so, everything is simple.
Second, when you describe a table, you only need to add a database name. Select wc. table. name from wc. table, wcw. table2.name

How to view the execution of stored procedures in the mysql database

Execute the Stored Procedure statement step by step !! View the results of each statement! 1
In this way, we can check whether the execution conditions are correct or not.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.