PL / SQL PROCEDURE名称已被现有对象使用

时间:2016-01-15 11:27:12

标签: plsql procedures

所以我写下了一个程序,该程序应该采用2个参数名称和死亡年龄。之后,它检查age的值是否为null,其中name是....如果为null,则应该更新表,如果没有给出以下消息。但在尝试执行查询后,我得到了一个

ORA-00955:名称已被现有对象使用 00955. 00000 - "名称已被现有对象使用"

我不知道如何解决的错误。

 SET SERVEROUTPUT ON

CREATE PROCEDURE set_death_age(input_PRES_NAME IN PRESIDENT.PRE_NAME%TYPE , input_DEATH_AGE IN PRESIDENT.DEATH_AGE%TYPE) IS

Dage PRESIDENT.DEATH_AGE%TYPE;

BEGIN

--Dage := &Enter_death_age;

            SELECT DEATH_AGE  INTO Dage
            FROM PRESIDENT
            WHERE PRES_NAME = input_PRES_NAME;


            IF Dage is null
            THEN

            UPDATE PRESIDENT
            SET DEATH_AGE = input_DEATH_AGE
            WHERE PRES_NAME = input_PRES_NAME;  
            DBMS_OUTPUT.PUT_LINE('Updated');
                    ELSE 
                    DBMS_OUTPUT.PUT_LINE('President is dead');
            END IF;

            EXCEPTION 
            WHEN NO_DATA_FOUND THEN
            DBMS_OUTPUT.PUT_LINE('No such president found');

            WHEN OTHERS THEN
            DBMS_OUTPUT.PUT_LINE('Errorrrrrrr');

END;

1 个答案:

答案 0 :(得分:1)

当你第一次编译它时,你创建它然后每次重新编译时都要替换它。

 SET SERVEROUTPUT ON

    CREATE OR REPLACE PROCEDURE set_death_age(input_PRES_NAME IN PRESIDENT.PRE_NAME%TYPE , input_DEATH_AGE IN PRESIDENT.DEATH_AGE%TYPE) IS

    Dage PRESIDENT.DEATH_AGE%TYPE;

    BEGIN

    --Dage := &Enter_death_age;

                SELECT DEATH_AGE  INTO Dage
                FROM PRESIDENT
                WHERE PRES_NAME = input_PRES_NAME;


                IF Dage is null
                THEN

                UPDATE PRESIDENT
                SET DEATH_AGE = input_DEATH_AGE
                WHERE PRES_NAME = input_PRES_NAME;  
                DBMS_OUTPUT.PUT_LINE('Updated');
                        ELSE 
                        DBMS_OUTPUT.PUT_LINE('President is dead');
                END IF;

                EXCEPTION 
                WHEN NO_DATA_FOUND THEN
                DBMS_OUTPUT.PUT_LINE('No such president found');

                WHEN OTHERS THEN
                DBMS_OUTPUT.PUT_LINE('Errorrrrrrr');

    END;