0
votes

When I try to compile this package, I get the error: PLS-00103: Encountered the symbol “BEGIN” when expecting one of the following: end function pragma procedure subtype type current cursor delete exists prior

Can anyone help me, please?

CREATE OR REPLACE PACKAGE PCK_TB_ESTADO
IS
  PROCEDURE PRC_INSERE
  (P_NM_REDE_FUNCIONARIO IN TB_FUNCIONARIO.NM_REDE_FUNCIONARIO%TYPE,
  P_DS_ESTADO IN TB_ESTADO.DS_ESTADO%TYPE,
  P_ID_UF IN TB_ESTADO.ID_UF%TYPE,
  P_MENS OUT VARCHAR2)
  BEGIN
    CREATE SEQUENCE SEQ_ESTADO
      MINVALUE 1
      MAXVALUE 99
      START WITH 1
      INCREMENT BY 1;
    INSERT INTO TB_ESTADO
    VALUES (SEQ_ESTADO.NEXTVAL,P_DS_ESTADO,P_ID_UF,SYSDATE,P_NM_REDE_FUNCIONARIO);
    COMMIT;
    EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
        ROLLBACK;
        P_MENS := 'Você tentou executar um comando INSERT ou UPDATE que criou um valor duplicado em um campo restrito por um index único.';
      WHEN OTHERS THEN
        ROLLBACK;
        P_MENS := 'Erro.';
  END;
END PCK_TB_ESTADO;
1
You're missing IS keyword before BEGINIncognito
I already tried with IS keyword and I got the same error.Guilherme Lima Pereira
I'm sure you already created the package spec. And this being Package Body, you need to write BODY in CREATE OR REPLACE PACKAGE BODY PCK_TB_ESTADO. Also, you can't directly create Sequence inside the procedure, that being a DDL command.Incognito
No. This is my package spec, the package body is another code that I already has created but not compiled yet.Guilherme Lima Pereira
If this is your package spec, then you don't need to write the code for procedure here! That's what goes in PACKAGE BODY. Spec just contains the signature of the procedures/functionsIncognito

1 Answers

4
votes

Here are the Issues:

  1. A Package Specification only contains the signature of the procedures/functions it is supposed to contain. The code for the procs/functions goes into the Package Body

  2. You cannot have a DDL statement directly inside your Procedure. You can however execute DDLs using EXECUTE IMMEDIATE

  3. The Procedure definition in the Package Body should have IS/AS keyword before BEGIN