memberStatus总是返回0.但是当我单独运行查询时,它可以正常工作。
DROP PROCEDURE IF EXISTS getMySubjectLists;
DELIMITER $$
CREATE PROCEDURE getMySubjectLists(
IN myID INT,
IN GID INT
)
BEGIN
DECLARE memberStatus INT DEFAULT 0;
SELECT COALESCE(status,0) into memberStatus from member_access where group_id = GID and subject_id = 0 and topic_id = 0 and subtopic_id = 0
and member_id = myID;
insert into apps_log values(0,memberStatus,GID,myID,"",now());
END$$
DELIMITER ;
为member_access创建表格如下。该过程不仅适用于此特定表。我尝试过其他表,但它确实有效。
CREATE TABLE `member_access` (
`seqno` int(11) NOT NULL AUTO_INCREMENT,
`mapid` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
`subject_id` int(11) NOT NULL,
`topic_id` int(11) NOT NULL,
`subtopic_id` int(11) NOT NULL,
`member_id` int(11) NOT NULL,
`access_code` int(11) DEFAULT '0',
`delegate_code` int(11) DEFAULT '0',
`specialid1` int(11) DEFAULT '0',
`specialid2` int(11) DEFAULT '0',
`specialid3` int(11) DEFAULT '0',
`status` int(11) DEFAULT '0',
`created` datetime DEFAULT NULL,
`updated` datetime DEFAULT NULL,
PRIMARY KEY (`seqno`),
KEY `indx1` (`mapid`,`access_code`,`status`),
KEY `mig1` (`mapid`,`member_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci