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

MySQL-- stored procedure

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Define a complex logic for batch processing of SQL statements, create a delimiter / / modification Terminator through a name store-- the stored procedure does not return a value of delimiter / /-put the Terminator; modify it to / / create procedure porc2 () begin-- executable statement insert into mm_users values (0Zhenxiaownagm.xxx'); select * from mm_users;end//-fill in the Terminator delimiter -restore the original Terminator to perform view-- View mysql.proc select db,name,type from mysql.proc; call-- call if the stored procedure does not have parameter parentheses, you can omit callproc ();-- execute stored procedure cursor.callproc ('stored object name') deletion in pymysql-- Delete drop procedure proc_stu;delete from mysql.proc where name = 'porc1'' -the difference between stored procedures and functions-- Courseware-- what are the restrictions on the use of functions-- select statements cannot be executed in functions-- functions cannot be executed by select statements other than select into-- select into assigns query results to a variable delimiter / / create function f4 (in an int,in b int) returns int begin-- defines a variable res declare res int default 0 -- assign the result of a + b to res select count (*) from mm_users into res;-- set res = a + b;-- return res return res; end / / delimiter -- using stored procedures to realize the disadvantage of not being able to call select statements in functions-- but stored procedures do not return values-- you can use parameters of type out to give stored procedures the function of returning multiple values. Stored procedures and functions are both compiled once and are cached. The next time they are used, they directly hit the compiled sql in the cache. There is no need for repeated compilation to reduce network interaction and reduce network access traffic-different point identifiers are different. The identifier of the function is function. Procedure: there is a return value in the procedure function, and there must be a return value, but the procedure has no return value, but you can set the parameter type (in). Out) to implement multiple parameters or return value functions using select calls, stored procedures need to use call calls select statements can be called in storage, but except for select. Select statements other than into can no longer be called in functions through in out parameters, so process-related functions are more flexible and can return multiple results. In actual development, you can choose to use function or stored procedure-parameter / return value-parameter type-in input type parameter according to your preference. The parameter of function or stored procedure defaults to the parameter of incoming type-the parameter of out outgoing type. Realize the function of multiple return values to the stored procedure-inout can be passed in or out. Generally, there is no need for a parameter to express multiple meanings, resulting in unclear semantics of the parameters. The maximum number of parameters of the function: 1024procedure p1 (in arg1 int, # let the stored procedure use out arg2 varchar (50) inout arg3 int) begin. End@i1 = "alex" # @ il references call p1 (1) @ i1, @ i2) # @ set a variable @ i1 = null

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