Search code examples
sqloracle-databasestored-proceduresplsqlora-00904

Basic Oracle question


I am new to oracle. When I create a stored procedure using:

CREATE OR REPLACE PROCEDURE PROCEDURE1 
AS
BEGIN

  SELECT FIRSTNAME,
         LASTNAME
    INTO FirstName,LastName
    FROM EMPLOYEE;

END PROCEDURE1;

i get the following errors:

PL/SQL Statement Ignored Identifier FIRSTNAME must be declared ORA-00904 Invalid identifier


Solution


  • I think the "AS" keyword won't work. If it doesn't work, then use "IS".
    Rest are fine and very good tips.

    If you need any help regarding PL/SQL, then you can have a look at this link. It is very simple and easy to understand;
    http://plsql-tutorial.com/

    This is my solution to the error which you are getting;

    CREATE OR REPLACE PROCEDURE PROCEDURE1 IS
      v_FIRSTNAME EMPLOYEE.FIRSTNAME%TYPE;
      v_LASTNAME EMPLOYEE.LASTNAME%TYPE;
      CURSOR EMPCURSOR IS
      SELECT FIRSTNAME, LASTNAME FROM EMPLOYEE;      
      BEGIN   
         IF NOT EMPCURSOR%ISOPEN THEN
             OPEN EMPCURSOR;
         END IF;
         LOOP
            FETCH EMPCURSOR INTO V_FIRSTNAME,V_LASTNAME;
            EXIT WHEN EMPCURSOR%NOTFOUND;
         END LOOP;
         IF EMPCURSOR%ISOPEN THEN
            CLOSE EMPCURSOR;
         END;
      END PROCEDURE1;
    

    You can also use DBMS_OUTPUT.PUT_LINE(V_FIRSTNAME || ','|| V_LASTNAME), inside the loop to display the output. but in order to do that, you first need to execute the command server output on