MySQL Advanced learning Note four: the definition of MySQL stored procedures, processing procedures and management of stored procedures! (Video serial Number: Advanced _11,12)

Source: Internet
Author: User

Knowledge Point five: definition of MySQL stored procedure conditions and process and management of stored procedures (11,12)

Define conditions and handling:

The definition and processing of a condition can be used to define the corresponding processing steps when a problem is encountered during processing.

DECLARE CONTINUE HANDLER for SQLSTATE ' error code value ' SET @ variable = variable Value

Management of stored procedures:

Changes to Stored procedures:
Alter{procedure | FUNCTION} sp_name

[Characteristic ...]

Characteristic:

{CONTAINS SQL | NO SQL | READS SQL DATA | Modifies SQL DATA}

| SQL SECURITY {definer| Invokey}
| COMMENT ' string ';

    Note: No SQL indicates that the subroutine does not contain SQL statements,

READS SQL data represents a statement in a subroutine that contains read data.

Modifies SQL data represents a statement in a subroutine that contains write data

SQL SECURITY {definer | Invokey} indicates who has permission to execute

Definer that only the definition can be executed by himself;

Invokey indicates that the caller can execute

COMMENT ' String ' is a comment message

  To view stored procedures under a database:

SHOW PROCEDURE STATUS WHERE db= ' database name ';

    View the list of stored procedures under the current database:

SELECT specific_name from Mysql.proc;

    To view the contents of a stored procedure:
SELECT specific_name,body from Mysql.procwhere specific_name = stored procedure name;

Or: SHOW CREATE PROCEDURE Stored procedure name.
  To delete a stored procedure:

DROP PROCEDURE IF exists stored procedure name

1 --defining conditions and handling2 --join is right, but execute an error, because if is one of userinfo and exists3DELIMITER//4 CREATE PROCEDUREP_insertdemo ()5 6 BEGIN7     INSERT  intoUserInfoVALUES(1,'UI','123');8     INSERT  intoEmployeesVALUES(5098,'1990-11-11','Uim','Jum','2000-11-12');9 END Ten // One  A DELIMITER; - Call P_insertdemo2 (); -  the  - --right. -DELIMITER// - CREATE PROCEDUREP_insertdemo2 () +  - BEGIN +     DECLARE CONTINUEHANDLER forSQLSTATE'23000' SET @x=1; A     INSERT  intoUserInfoVALUES(1,'UI','123'); at     INSERT  intoEmployeesVALUES(5098,'1990-11-11','Uim','Jum','M','2000-11-12'); - END  - // -  - DELIMITER; -Call P_insertdemo2 ();
defining conditions and processing process tests

MySQL Advanced learning Note four: the definition of MySQL stored procedures, processing procedures and management of stored procedures! (Video serial Number: Advanced _11,12)

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.