码迷,mamicode.com
首页 > 数据库 > 详细

MYSQL- 存储过程示例

时间:2015-03-31 12:36:02      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

  最近需要用到MYSQL,没耐心从头到尾,慢慢了解了,需要什么直接百度,直接了解,从实战中学习。

  看一下MYSQL存储过程的示例:

CREATE PROCEDURE plogin
(
    p_username char(15),
    p_password char(32),
    p_ip char(18),
    p_logintime datetime
)
LABEL_PROC:
BEGIN    
 
    DECLARE v_uid mediumint(8);  
    DECLARE v_realpassword char(32);     
    DECLARE v_nickname varchar(30);    
    DECLARE v_oltime smallint(6);      
   
    SELECT u.uid, u.password, f.nickname, u.oltime INTO v_uid, v_realpassword, v_nickname, v_oltime
    FROM cdb_members u INNER JOIN cdb_memberfields f ON f.uid = u.uid WHERE u.username = p_username;   
   
    IF (v_uid IS NULL) THEN
        SELECT 2 AS ErrorCode;
        LEAVE LABEL_PROC;
    END IF;
 
    IF (p_password <> v_realpassword) THEN
        SELECT 3 AS ErrorCode;
        LEAVE LABEL_PROC;
    END IF;
 
    UPDATE ipsp_userexpands SET lastloginip = p_ip, lastlogintime = p_logintime WHERE uid = v_uid;
 
    SELECT 0 AS ErrorCode, v_uid AS uid, v_nickname AS nickname, v_oltime AS oltime;
 
END LABEL_PROC //

  调用示例是 call plogin(‘参数1‘,‘参数2‘,‘参数3‘,‘参数4‘);

 

MYSQL- 存储过程示例

标签:

原文地址:http://www.cnblogs.com/cxeye/p/4380248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!