Home > Database > Mysql Tutorial > body text

MySQL简略存储过程示例(持续追加)

WBOY
Release: 2016-06-07 16:25:04
Original
1127 people have browsed it

MySQL简单存储过程示例(持续追加) 示例一: 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 I

MySQL简单存储过程示例(持续追加)
示例一:
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 a.name=myname,a.age=myage WHERE a.id=myid;
END IF
Copy after login

示例二:
CREATE PROCEDURE getShang(IN worknum VARCHAR(10),OUT outName VARCHAR(20))

BEGIN
DECLARE ret int;
DECLARE p1 VARCHAR(10);
DECLARE p2 VARCHAR(10);

set ret = (SELECT gt.iparentgroup
FROM grouptbl gt,groupmembertbl gmt
WHERE gt.igroupid = gmt.igroupid
AND gmt.smemberid = worknum);

if ret = 0

THEN
 
 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
Copy after login

调用:
CALL getShang('ABC1122',@groupName);
SELECT @groupName;
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template