Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start with 0 for Mysql stored procedures

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I don't know if you know anything about similar articles about how Mysql stored procedures start from zero. Today, I'm here to tell you a little bit about it. If you are interested, let's take a look at the text. I'm sure you'll get something after seeing how Mysql stored procedures start from 0.

1. First of all, you have to understand that mysql is also a language, and it can also write programs and support logical judgment, if,elseif,else,switch,while and so on.

2. Mysql assigns the value operation of a variable: set @ a = 1; check that the variable is select @ a

3. When you create a stored procedure, you have to select the database of Mysql before you can operate it, such as creating a

(1) create procedure hanshuming () / / method body: select concat (@ a world')

Concat is a link string, set @ a = "Hello"

(2) the call is call hanshuming ()

4. a small example of a simple entry-level stored procedure

Mysql > DELIMITER / first you need to escape to prevent mysql from executing your statement as a sql statement

Mysql > CREATE PROCEDURE proc1-- proc1 stored procedure name

-> (IN parameter1 INTEGER)

-> BEGIN

-> DECLARE variable1 CHAR (10);-- declare is a named variable

-> IF parameter1 = 17 THEN

-> SET variable1 = 'birds'

-> ELSE

-> SET variable1 = 'beasts'

-> END IF

-> INSERT INTO table1 VALUES (variable1)

-> END

-> / /

Mysql > DELIMITER

5. View the stored procedures under the current database

(1) the show procedure status where db=' database name'G;-G means formatting

(2) View the details of the current stored procedure

Show create procedure database name. Stored procedure name G

(3) Delete stored procedures

Drop procedure sp_name-name of the stored procedure

DROP PROCEDURE-delete everything, don't use it easily

6. The defined variable is only used in the stored procedure, and the excess is gone. The following figure is an example, that is, it is gone after end.

7. Operation of inout

When you call this stored procedure, you can't put the data directly in the method, you have to set the value of the variable, and then put the variable in.

If you put it directly, you will report an error.

It should be called like this

After reading this article on how to start Mysql stored procedures from 0, what do you think? If you want to know more about it, you can continue to follow our industry information section.

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: 0

*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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report