0

so i wrote down a procedure which should take 2 parameters name and death age. After that it checks if the value of the age is null where name is ... . If it is null it should update the table if not give a following message. But after trying to execute the query i get an

ORA-00955: name is already used by an existing object 00955. 00000 - "name is already used by an existing object"

errors which i dont know how to solve.

 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 Answers1

1

When you compile it for the first time you create it and then you are replacing it every time you re-compile.

 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;