Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement mysql stored procedure

Shulou Source: shulou.com Published: 2022-06-01 05:50:27 11月30日 Update

This article mainly explains "how to implement mysql stored procedures". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to implement mysql stored procedures".

Stored procedure

Stored procedures can be thought of as SQL functions and can pass parameters (variables)

A stored procedure can encapsulate a long string of SQL code into a module, a class class, and call loops.

It is not recommended to use stored procedures. If you really need to pass parameter variables, it is recommended to use the parameters of python.

Stored procedure-mysql example

The steps of the sample procedure are explained in detail:

By parameter: auto_tbcrm_order

Delete temporary table: temp_tbcrmorder_tbcrm

Create a temporary table: temp_tbcrmorder_tbcrm, and the data source comes from all the contents of the auto_tbcrm_order table

# consolidation of order data in Taobao system

Drop procedure if exists insert_update_tbcrm

Create procedure insert_update_tbcrm (in tbcrmorder_name varchar)

BEGIN

# # order data preprocessing

SET @ STMT: = CONCAT ("drop table if exists temp_tbcrmorder_tbcrm")

PREPARE STMT FROM @ STMT

EXECUTE STMT

SET @ tbl_name = CONCAT (tbcrmorder_name)

SET @ STMT: = CONCAT ("create table temp_tbcrmorder_tbcrm", "select * from", @ tbl_name, ";")

PREPARE STMT FROM @ STMT

EXECUTE STMT

# create index id on temp_tbcrmorder_tbcrm (orderid,orderstatus)

# ALTER TABLE temp_tbcrmorder_tbcrm ADD unique KEY (orderid)

End

Call insert_update_tbcrm ('auto_tbcrm_order')

The above stored procedure, but there are two stored procedure steps

Thank you for your reading, the above is the content of "how to implement mysql stored procedures". After the study of this article, I believe you have a deeper understanding of how to achieve mysql stored procedures, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Procedures storage parameters content data learning variables suggestions steps examples orders two code functions that is ideas situations data sources articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Docker NVidia MySQL