MySQL stored procedures, views---Create, invoke, delete

Source: Internet
Author: User

The SQL Server database has been used before, and has recently been exposed to MySQL by chance. Here is a summary of the "Create, invoke, delete" Examples of MySQL stored procedures, views

======================================= Stored Procedure ==================================

/* Create a stored procedure */
DELIMITER $$/* To avoid conflicts, first use "DELIMITER &&" to set the MySQL terminator to &&*/
Use ' dataname ' $$/*dataname--> database name */
Drop PROCEDURE if EXISTS ' AA ' $$/* Determine if the stored procedure exists (delete if present) */
CREATE definer= ' root ' @ '% ' PROCEDURE ' AA ' (str_id varchar)/*aa--> stored procedure name; str_id VARCHAR--and parameters */
BEGIN
SELECT * from Tj_archive WHERE id=str_id; /* SQL script executed by */
end$$
DELIMITER; /* Finally re-use "DELIMITER;" To restore the Terminator component number */

/* View Stored procedures */
Call ' AA ' (' D1608220023 ')

/* Delete stored procedures */
DROP PROCEDURE ' AA '

======================================= View ==================================

--Create a view
CREATE VIEW MyView as
SELECT
Case Sex-Applicability 0: Unisex 1: Male 2: Female
When sex= ' man ' then 1--For male
When sex= ' women ' then 2--for women
When sex= ' Universal ' then 0--unisex
END as XB
From MyTable--table
--where--filter conditions

--View View
--select * from MyView

MySQL stored procedures, views---Create, invoke, delete

Related Article

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.