MYSQL- 存储过程示例
最近需要用到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');