CREATE OR REPLACE PROCEDURE FinishedPercent (uinput varchar2) IS
CURSOR obsah IS
SELECT * FROM DUNGEON
NATURAL JOIN MY_CHARACTER;
printObsah obsah%ROWTYPE;
chartofind MY_CHARACTER.char_name%TYPE;
dokoncene int;
vsetky int;
BEGIN
dokoncene := 0;
vsetky := 0;
SELECT DUNGEON.dungeon_ID INTO vsetky FROM DUNGEON;
SELECT MY_CHARACTER.char_name
INTO chartofind
FROM MY_CHARACTER
INNER JOIN DUNGEON ON uinput = DUNGEON.dungeon_name
INNER JOIN CAVE ON CAVE.dungeon_sub = DUNGEON.dungeon_ID;
open obsah;
loop
fetch obsah INTO printObsah;
exit WHEN obsah%NOTFOUND;
if (DUNGEON.status = 1) THEN
dokoncene := dokoncene + 1;
end if;
end loop;
dbms_output.put_line('Pre postavu ' || uinput || 'ostava ' || (vsetky - dokoncene) || 'questov, co je ' || (dokoncene * 100)/vsetky || 'percent');
EXCEPTION
WHEN ZERO_DIVIDE THEN
dbms_output.put_line('Pre postavu ' || uinput || 'ostava ' || (vsetky - dokoncene) || 'questov, co je 0 percent');
WHEN OTHERS THEN
raise_application_error(-20001, 'An error encountered: ' || SQLCODE || SQLERRM);
END;
/
这是我的程序,基本上它应该选择一个角色并打印出已完成的地下城百分比(可用于他的全部)。
我收到以下错误:
错误(16,5):PL / SQL:语句被忽略
错误(16,17):PLS-00357: 此表中不允许使用表,视图或序列参考'DUNGEON.STATUS' 上下文
基本上在我的表DUNGEON.status中,它是1或0的整数,具体取决于它的完成情况。在我的程序中,我只想要一个简单的循环,当地牢完成时会增加'dokoncene'参数。知道我做错了什么吗?
答案 0 :(得分:0)
如果没有任何表格定义或示例数据,很难提供答案,但您似乎正在尝试这样做:
CREATE OR REPLACE PROCEDURE FinishedPercent (
uinput varchar2
)
IS
percentage NUMBER(3,2);
BEGIN
SELECT AVG( CASE status WHEN 1 THEN 1 ELSE 0 END ) * 100
INTO percentage
FROM DUNGEON
WHERE name = uinput;
DBMS_OUTPUT.PUT_LINE( percentage );
END;
/