mysql--Stored Procedures

Source: Internet
Author: User

Defines a complex logic for batch processing of SQL statements, creating delimiter //  modification terminators through a name store--  stored procedures have no return value delimiter //     ----  put Terminator; Modify to//create procedure porc2 () begin--  executable statement insert into mm_users  values  (0, ' xiaownag ', ' xxx ');select * from mm_users;end//        ----  Fill in Terminator delimiter ;   ----  Restore original terminator to perform view--  view   mysql.proc   select db,name,type from mysql.proc; Call--  call   If stored procedure has no parameters   parentheses can omit Call proc ();--Execute stored procedure     cursor.callproc (' Store object name ') in Pymysql delete--  Delete drop procedure proc_stu;delete from mysql.proc where name =  ' Porc1 '; -  the difference between stored procedures and functions-  courseware--  function when use what restrictions  -- select  statements are not able to execute in functions  --  functions except   Other  select  statements other than Select into are not able to execute  -- select into  is to assign the result of a query to a variable   Delimiter // create fuNction f4 (In a int,in b int)  returns int begin --  define a variable  res declare res int default 0; --  assign the results of  a + b to   Res select count (*)  from mm_users into res; -- set res =  a + b; --  back  res return res; end // delimiter ;  --  using stored procedures to implement a function that cannot invoke  select  statement's drawbacks  --  but the stored procedure does not return a value  --  can be  out The   type of parameters to implement multiple return values for a stored procedure-  the same point stored procedures and functions are for repeatable execution of the collection of  sql  statements for the database. Stored procedures and functions are compiled once and are cached. The next use will directly hit the cache has been compiled  sql, do not need to reduce network interaction, reduce network access traffic-  different points, the identifier of the function is the  function,  process: The procedure function has a return value and must have a return value, but the procedure does not return a value, but you can implement multiple parameters by setting the parameter type (in,out) or return value function using  select  call, the stored procedure needs to use the  call The   call select  statement can be called in the store, but  select  statements other than  select ... into  cannot be called in a function  in out  parameters, the process-related functions are more flexible and can return multipleResults in the actual development according to personal preferences choose to use functions or stored procedures-  parameter/return value--  parameter type-- in  parameters of the incoming type, function or stored procedure parameters   default is the parameter of the incoming type-- Parameters of the  out  outgoing type,  the ability to implement multiple return values for a stored procedure-- inout   can be passed in and out   generally not   a parameter to express multiple meanings, The semantics of the arguments are not clear enough   the maximum number of parameters for the function:  1024procedure p1 (    in arg1 int,    #  let stored procedures internal use     out arg2 varchar      Inout arg3 int) begin    ...end@i1 =  "Alex" #  @il   citation call  P1 (1,  @i1,  @i2)   # @ set a variable @i1= null

mysql--Stored Procedures

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.