Simple MySQL Stored Procedure example (continuous append)

Source: Internet
Author: User
Tags stored procedure example
Simple MySQL Stored Procedure Example 1: CREATEPROCEDUREtest (INmyidINT (3), INmynameVARCHAR (22), INmyageINT (3) ifmyid0THENINSERTINTOa (name, age) VALUES (myname, myage); ELSEUPDATEaSETa. namemyname,. agemyageWHEREa. idmyid; ENDI

Example 1 of a simple MySQL Stored PROCEDURE (continuous append): create procedure test (IN myid INT (3), IN myname VARCHAR (22), IN myage INT (3 )) if myid = 0 then insert into a (name, age) VALUES (myname, myage); else update a SET. name = myname,. age = myage WHERE. id = myid; END I

Simple MySQL Stored Procedure example (continuous append)
Example 1:
CREATE PROCEDURE test(IN myid INT(3),IN myname VARCHAR(22),IN myage INT(3))if myid=0THEN INSERT INTO a(name,age) VALUES(myname,myage);ELSE UPDATE a SET a.name=myname,a.age=myage WHERE a.id=myid;END IF

Example 2:
CREATE PROCEDURE getShang(IN worknum VARCHAR(10),OUT outName VARCHAR(20))BEGINDECLARE ret int;DECLARE p1 VARCHAR(10);DECLARE p2 VARCHAR(10);set ret = (SELECT gt.iparentgroupFROM grouptbl gt,groupmembertbl gmtWHERE gt.igroupid = gmt.igroupidAND gmt.smemberid = worknum);if ret = 0THEN  set p1=(SELECT gt.sgroupname FROM grouptbl gt,groupmembertbl gmt WHERE gt.igroupid = gmt.igroupid AND gmt.smemberid = worknum); SET outName = p1;ELSE  set p2 = ( SELECT grouptbl.sgroupname FROM grouptbl WHERE grouptbl.igroupid =  (SELECT gt.iparentgroup FROM grouptbl gt,groupmembertbl gmt WHERE gt.igroupid = gmt.igroupid AND gmt.smemberid = worknum) ); SET outName = p2;END IF;END

Call:
CALL getShang('ABC1122',@groupName);SELECT @groupName;

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.