MySQL stored procedures, definition of temporary variables, if, Case

Source: Internet
Author: User
-- MySQL stored procedure/* Set @ result = 0; Create procedure login (-- defines parameters, including in, out, And inout types in user varchar (10 ), in pass varchar (10), out result INT) Begin declare passd varchar (10); -- declare declares temporary variables and types, and then assigns values using set, the declare temporary variables can only be placed in the begin end region, and their scope is only in the begin end region. The set @ variable defines the global variable select password into passd from login where username = user; if passd like pass then -- If statement, end if should be followed, just like adding end case after case select 'login SUCCESS 'as massage; Set result = 1; elseselect 'login failed' as message; Set result = 0; end if; end; */-- call the Stored Procedure Call login ('root', 'root', @ result ); -- delete the Stored Procedure drop procedure logincreate procedure translate (id int) begincase idwhen 1 then select 'one' as Trans; when 2 thenselect 'two' as Trans; when 3 then select 'three 'as Trans; elseselect 'no trans' as Trans; end case; end;/* There are two use cases: 1. conditional variables select name, casewhen age> 10 then xxxxxelsexxxxend case2. conditional variables select name, Case agewhen> 10 then XXX else xxxxxsend case */

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.