How to identify and correct error 00302 in Oracle? [closed]

-1

How can I correct an error of this nature (ERROR 00302) and how to know the line in which the error is in Oracle SQL Developer?

Error(16,6): PL/SQL: Statement ignored
Error(16,52): PLS-00302: component 'NOME_PESSOA' must be declared
Error(17,6): PL/SQL: Statement ignored
Error(17,52): PLS-00302: component 'ID_ENDERECO' must be declared 

CREATE OR REPLACE TRIGGER T_GERA_ENDERECO_AFTER AFTER INSERT ON pessoa

DECLARE
   -- cria o tipo para variável que armazena o conteúdo do package
   TYPE tbPessoaPackage IS TABLE OF pessoa%ROWTYPE INDEX BY BINARY_INTEGER;
   tbPessoa   tbPessoaPackage;
   x           BINARY_INTEGER; --indice

 BEGIN
   -- atribui ao índice o primeiro valor do package
   x := pkg_pessoa.vPessoa.FIRST;
   -- limpa a var criada
   tbPessoa.DELETE;

   -- adiciona todos os registros do package na variável criada
   WHILE x IS NOT NULL LOOP
     tbPessoa(x).id_pessoa := pkg_pessoa.vPessoa(x).id_pessoa;
     tbPessoa(x).nome_pessoa := pkg_pessoa.vPessoa.nome_pessoa;
     tbPessoa(x).id_endereco := pkg_pessoa.vPessoa.id_endereco;
     x := pkg_pessoa.vPessoa.NEXT(x); -- incrementa o valor do índice
   END LOOP;

   pkg_pessoa.vPessoa.DELETE; -- limpa o package
   x := tbPessoa.FIRST; -- atribui ao índice o primeiro valor

   -- loop para percorrer todos os registros do package
   WHILE x IS NOT NULL LOOP
     -- insert na tabela endereco, com o nome da rua sendo Rua + nome da pessoa (ex: Rua do Felisberto)
     BEGIN
       INSERT INTO endereco (id_endereco,lograddouro) values (seq_endereco.nextval, 'Rua do ' || tbPessoa(x).nome_pessoa);
     EXCEPTION
       WHEN OTHERS THEN
         RAISE_APPLICATION_ERROR(-20001
                                ,'Não foi possível inserir os dados na tabela ENDERECO. Trigger: T_GERA_ENDERECO_AFTER ' || SQLERRM);
     END;
     -- update na tabela Pessoa, para setar o valor do id_endereco da Pessoa com o valor do id do endereço gerado no insert acima
     BEGIN
       UPDATE pessoa p SET p.id_endereco = seq_endereco.currval
        WHERE p.id_pessoa = tbPessoa(x).id_pessoa;
     EXCEPTION
       WHEN OTHERS THEN
         RAISE_APPLICATION_ERROR(-20002
                                ,'Não foi possível atualizar os dados na tabela PESSOA. Trigger: 
                                T_GERA_ENDERECO_AFTER ' || SQLERRM);
     END;
     -- atualiza valor do indice para o proximo registro
     x := tbPessoa.NEXT(x);
   END LOOP;

 END;
 /
    
asked by anonymous 19.07.2016 / 20:23

1 answer

2

An error PLS-00302 in Oracle PL / SQL means that some component used in the statement was not declared.

The most common reasons for this to happen are:

  • Forget to declare variables
  • Declare variables with the same name as some artifact (eg, you have a SCHEMA and an any object with the same name)
  • Typos (declaration and use with different names).

The errors point to the row number and column number where the error occurred. For example (16,6) means sixteenth row, sixth column. Note that the line is not necessarily counted from the beginning of the window, but rather from the executed block.

    
19.07.2016 / 21:17