《MysqL应用MysqL存储过程简单实例》要点:
本文介绍了MysqL应用MysqL存储过程简单实例,希望对您有用。如果有疑问,可以联系我们。
MysqL数据库例一,MysqL存储过程:
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
MysqL数据库例二,MysqL存储过程:
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
MysqL数据库调用:
SELECT @groupname;
MysqL数据库注:例一和例二中因为已经传入了参数值如:IN myID INT(3),那么就不必重复定义如:DECLARE myID int;不然这个myID应该始终是默认值0!!!
MysqL数据库例三,MysqL存储过程:
IN personname VARCHAR(20),
IN project VARCHAR(100),
IN utilizationPercent float(3,2),
IN sTime date,
IN special VARCHAR(250)
)
BEGIN
DECLARE pjID INT;
DECLARE utilizationID INT;
set pjID = (
SELECT ppt.projectPersonID
FROM projectpersontbl ppt
WHERE ppt.projectID =
(
SELECT pt.projectID
FROM projecttbl pt
WHERE pt.projectname = project
)
AND ppt.personNumber =
(
SELECT p.worknum
FROM person p
WHERE p.name = personname
)
);
set utilizationID = (
SELECT put.utilizationID
FROM personutilizationtbl put
WHERE put.projectPersonID = pjID
AND put.startTime = sTime
);
if utilizationID is null
THEN
INSERT INTO personutilizationtbl(projectPersonID,utilizationPercent,startTime,specialExplanation)
VALUES(pjID,sTime,special);
ELSE
UPDATE personutilizationtbl SET personutilizationtbl.utilizationPercent = utilizationPercent,
personutilizationtbl.specialExplanation = special,personutilizationtbl.startTime = sTime
WHERE personutilizationtbl.utilizationID = utilizationID;
END IF;
END 总结
以上是内存溢出为你收集整理的Mysql应用mysql存储过程简单实例全部内容,希望文章能够帮你解决Mysql应用mysql存储过程简单实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)