我尝试在我的Oracle数据库中创建一个过程,但无法实现将查询结果分配给我的变量.这是我正在尝试调试的内容:
create or replace PROCEDURE PCD_COMBAT (identifier_perso NUMBER,identifier_advers NUMBER) AS ATT_PERSO NUMBER; OFF_PERSO NUMBER; DEF_ADVERS NUMBER; BEGIN OFF_PERSO := SELECT OFFENSE_PERSO FROM PERSONNAGE WHERE ID_PERSO = identifier_perso; DEF_ADVERS := SELECT DEFENSE_ADVERSAIRE FROM PERSONNAGE WHERE ID_ADVERSAIRE = identifier_advers; ATT_PERSO := OFF_PERSO - DEF_ADVERS; IF ATT_PERSO < 1 { ATT_PERSO := 1 }; END PCD_COMBAT;
它在Oracle Developper中清楚地表明,我的Select并没有让他高兴,也无法弄明白为什么.我读过的Oracle库,论坛和代码示例并没有多大帮助.
您需要使用SELECT INTO. PL / sql中没有大括号你需要使用THEN和END IF.我不太清楚你对结果做了什么.你想要还给它吗?那你需要一个功能.它应该看起来像这样(未经测试):
原文链接:https://www.f2er.com/oracle/205016.htmlcreate or replace FUNCTION PCD_COMBAT (identifier_perso NUMBER,identifier_advers NUMBER) RETURN NUMBER AS ATT_PERSO NUMBER; OFF_PERSO NUMBER; DEF_ADVERS NUMBER; BEGIN SELECT OFFENSE_PERSO INTO OFF_PERSO FROM PERSONNAGE WHERE ID_PERSO = identifier_perso; SELECT DEFENSE_ADVERSAIRE INTO DEF_ADVERS FROM PERSONNAGE WHERE ID_ADVERSAIRE = identifier_advers; ATT_PERSO := OFF_PERSO - DEF_ADVERS; IF ATT_PERSO < 1 THEN ATT_PERSO := 1; END IF RETURN ATT_PERSO; END PCD_COMBAT;