oracle “找不到数据”错误,我不明白原因

pftdvrlh  于 2022-12-22  发布在  Oracle
关注(0)|答案(1)|浏览(145)

我收到一个问题,我的代码,这是抛给我这个错误,我不知道为什么,因为它没有任何意义,如果你们中的任何人可以帮助我,你会是一个救生员。
我还没有真正尝试过任何东西,因为我甚至不知道从哪里开始,至少并试图解决这个问题,我找不到任何不一致的代码或任何东西,我不知道为什么它指出没有数据在声明部分时,事实上有。
声明 * 第1行错误:ORA-01403:未发现数据ORA-06512:在第7行
'设置服务器输出打开

DECLARE

v_newgoal donor.yrgoal%TYPE;
v_idno donor.idno%TYPE;
v_name donor.name%TYPE;
v_yrgoal donor.yrgoal%TYPE;

BEGIN

 SELECT idno, name, yrgoal
 INTO v_idno, v_name, v_yrgoal
 FROM donor
 WHERE v_idno = 11111;

 IF v_yrgoal > 500 THEN
  v_newgoal := v_yrgoal * 2;
 ELSIF v_yrgoal < 500 THEN
  v_newgoal := v_yrgoal + 250;
 ELSE
  dbms_output.put_line('Error: Not Proceeding.');

 END IF;

 UPDATE donor
 SET yrgoal = v_newgoal
 WHERE idno = 11111;
 dbms_output.put_line(v_idno||' '||v_name||' '||v_yrgoal);

END;
/
SET SERVEROUTPUT OFF

'

omhiaaxx

omhiaaxx1#

DECLARE
    v_newgoal donor.yrgoal%TYPE;    -- is Null
    v_idno donor.idno%TYPE;         -- is Null
    v_name donor.name%TYPE;         -- is Null
    v_yrgoal donor.yrgoal%TYPE;     -- is Null
BEGIN
    SELECT idno, name, yrgoal           -- >> NO_DATA_FOUND exception raised here
    INTO v_idno, v_name, v_yrgoal       -- Select ... INTO ... must return something
    FROM donor                          -- (when there is no row returned) >>> NO_DATA_FOUND  >>> could be handled in the EXCEPTION section below
            --WHERE v_idno = 11111;     -- this means "WHERE Null = 11111" - change the line to "WHERE idno = 11111"
    WHERE IDNO = 11111;                     

    IF v_yrgoal > 500 THEN
        v_newgoal := v_yrgoal * 2;
    ELSIF v_yrgoal < 500 THEN
        v_newgoal := v_yrgoal + 250;
    ELSE    -- if v_yrgoal is equal to 500 then v_newgoal will stay Null - don't think you want that
        dbms_output.put_line('Error: Not Proceeding.');  -- just message with no stopping --> UPDATE will be executed
    END IF;

    UPDATE donor
    SET yrgoal = v_newgoal  -- possible Null value
    WHERE idno = 11111;
    
    dbms_output.put_line(v_idno||' '||v_name||' '||v_yrgoal);
EXCEPTION                   -- EXCEPTION section - a place to handle different kinds of errors
    WHEN NO_DATA_FOUND THEN
        dbms_output.put_line('some info about the ERR');
    WHEN OTHERS THEN
        ... do something else ...
END;

相关问题