MySQL IF语句返回false而不是true

时间:2017-09-08 17:39:19

标签: mysql

我试着问这个没有答案,但这可能是我的错,也许我没有问正确的问题,所以我决定再试一次。

我创建了一个函数,该函数应该返回损坏最高的法术的ID。我是这样写的:

DELIMITER // CREATE FUNCTION getSpellMaxDmgID ( pCharID` int(11)) 返回int(11) 确定性 BEGIN

DECLARE pdmgpts int(11) DEFAULT 0;
DECLARE pdmgprstp int(11) DEFAULT 0;
DECLARE pdmgmaxspellid int(11) DEFAULT 0;

IF (SELECT MAX(`damage_points`) FROM `spell` WHERE `spell`.`spell_id` IN( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`))!=NULL THEN
SET pdmgpts=(SELECT MAX(`damage_points`) FROM `spell` WHERE `spell`.`spell_id` IN( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`));
END IF;
IF (SELECT MAX(`damage_per_step`) FROM `spell` WHERE `spell`.`spell_id` IN( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`))!=NULL THEN
SET pdmgprstp=(SELECT MAX(`damage_per_step`) FROM `spell` WHERE `spell`.`spell_id` IN( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`));
END IF;
IF pdmgpts>=pdmgprstp THEN
IF (SELECT `spell_id` FROM `spell` WHERE `spell`.`damage_points`=pdmgpts AND `spell`.`spell_id` IN ( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`) LIMIT 1)!=NULL THEN
SET pdmgmaxspellid=(SELECT `spell_id` FROM `spell` WHERE `spell`.`damage_points`=pdmgpts AND `spell`.`spell_id` IN ( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`));
END IF;
ELSE
IF (SELECT `spell_id` FROM `spell` WHERE `spell`.`damage_per_step`=pdmgprstp AND `spell`.`spell_id` IN ( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`) LIMIT 1)!=NULL THEN
SET pdmgmaxspellid=(SELECT `spell_id` FROM `spell` WHERE `spell`.`damage_per_step`=pdmgprstp AND `spell`.`spell_id` IN ( SELECT `spell_id` FROM `character_spell` WHERE `character_spell`.`character_id`=`pCharID`));
END IF;
END IF;

RETURN pdmgmaxspellid;

END; // DELIMITER;`

好吧,所以当我单独测试所有if语句时,如果我使用的是具有法术的角色(类似magelike类),它们都会给我一个值,否则,它们会返回null。现在,我正在使用类似角色的mage来测试函数,是的,如果查询给我一个非null值,则单独测试,但是当我尝试调用该函数时,它只给出了我为{{1}设置的默认值}。出于某种原因,即使我的陈述给我一个值,如果只是看到它们是假的而且没有做我想做的事情。有人在这看到问题吗?

这里我有与结果一起使用的陈述:

pdmgmaxspellid damage_points SELECT MAX(拼写) FROM咒语WHERE spell_id . spell_id IN( SELECT character_spell FROM character_spell WHERE character_id . Result

=8); damage_per_step SELECT MAX(拼写) FROM拼写WHERE spell_id . spell_id IN( SELECT character_spell FROM character_spell WHERE character_id . Result

=8) spell_id SELECT拼写FROM咒语WHERE damage_points .咒语=30 AND spell_id . spell_id IN ( SELECT character_spell FROM {character_spell {1}} {character_id {1}} 可悲的是,我不能发布超过两个链接,但是当我说结果是43时,你可以接受我的话。

WHERE spell_id .拼写=8) LIMIT 1咒语SELECT damage_per_step FROM咒语WHERE spell_id . spell_id =10 AND character_spell . {character_spell {1}} {character_id {1}} 与上面相同,结果是13。

0 个答案:

没有答案