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;
Here are the Issues:
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
You cannot have a DDL statement directly inside your Procedure. You can however execute DDLs using EXECUTE IMMEDIATE
The Procedure definition in the Package Body should have IS/AS keyword before BEGIN
Related
I'm making a package to collect some functions in the same place. But while I attempt to create the body it always has an error.
I have tried everything I know, but it doesn´t matter how much do I try it always gives me the same error
This is my package which does not bring me any error.
create or replace PACKAGE talde_paquete AS
procedure editaldeak(Equipo Taldeak.Kod_taldea%TYPE, Nombre Taldeak.izena%TYPE, Localidad Taldeak.Herria%TYPE, Correo taldeak.helbide_elektronikoa%TYPE,Campo Taldeak.Zelaia%TYPE);
procedure equipopartidos(Equipo partidak.talde1%TYPE);
END talde_paquete;
And this is my package body which is the one who brings me always the same error
CREATE OR REPLACE PACKAGE BODY talde_paquete
IS
procedure editaldea(Equipo Taldeak.Kod_taldea%TYPE, Nombre Taldeak.izena%TYPE, Localidad Taldeak.Herria%TYPE, Correo taldeak.helbide_elektronikoa%TYPE,Campo Taldeak.Zelaia%TYPE)
AS
VTaldea NUMBER(1);
Taldenoexist EXCEPTION;
BEGIN
SELECT COUNT(Kod_Taldea) INTO VTaldea FROM Taldeak WHERE Kod_Taldea=Equipo;
IF VTaldea=1 THEN
UPDATE Taldeak SET Izena=Nombre, Herria=Localidad, Helbide_Elektronikoa=Correo, Zelaia=Campo WHERE Kod_taldea=Equipo;
ELSE
RAISE Taldenoexist;
END IF;
EXCEPTION
WHEN Taldenoexist THEN
DBMS_OUTPUT.PUT_LINE('Taldea ez da existitzen');
END editaldea;
procedure equipopartidos(Equipo partidak.talde1%TYPE)
IS
CURSOR PartidoEquipo IS
SELECT Talde1, Talde2, P_Data FROM Partidak WHERE Talde1 LIKE Equipo OR Talde2 LIKE Equipo;
E1 Partidak.Talde1%TYPE;
E2 Partidak.Talde2%TYPE;
Fecha Partidak.P_Data%TYPE;
existe NUMBER(3);
Taldexist EXCEPTION;
BEGIN
SELECT COUNT(Talde1) INTO existe FROM partidak WHERE Talde1=Equipo OR Talde2=Equipo;
IF (existe>0)THEN
OPEN PartidoEquipo;
FETCH PartidoEquipo INTO E1,E2,Fecha;
WHILE PartidoEquipo%FOUND LOOP
DBMS_OUTPUT.PUT_LINE(E1||' taldeak '||E2||' taldearen aurka jokatuko du '||Fecha);
FETCH PartidoEquipo INTO E1,E2,Fecha;
END LOOP;
CLOSE PartidoEquipo;
ELSE
RAISE Taldexist;
END IF;
EXCEPTION
WHEN Taldexist THEN
DBMS_OUTPUT.PUT_LINE('Taldea ez da existitzen');
END equipopartidos;
END talde_paquete;
/
And here is the error that I get when I'm attempting to run the body script.
LINE/COL ERROR
--------- -------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
1/14 PLS-00905: object BIZKAIABASKET.TALDE_PAQUETE is invalid
1/14 PLS-00304: cannot compile body of 'TALDE_PAQUETE' without its specification
Errors: check compiler log
#hotfix is absolutely right, the error message when compiling is quite clear. The definition of the procedures in the body must be the same as the one defined in the header, I notice that there is a difference in the name editaldeak vs editaldea
I'm trying to call the following stored procedure...
CREATE OR REPLACE PROCEDURE PRC_EXAMEN_SUELDO(fecha_hoy varchar2)
AS
BEGIN
IF fecha_hoy= 'WEDNESDAY' then
RAISE_APPLICATION_ERROR(-20777, 'Los ' || fecha_hoy ||' no se puede cambiar el sueldo');
END IF;
END;
...inside this trigger:
CREATE OR REPLACE TRIGGER TRG_EXAMEN_SUELDO
BEFORE UPDATE OF SALARY ON EMPLOYEES
FOR EACH ROW
DECLARE
HOY VARCHAR(50);
BEGIN
HOY:= TO_CHAR (SYSDATE, 'DAY');
execute PRC_EXAMEN_SUELDO (HOY);
END;
But it throws the following error:
LINE/COL ERROR
--------- -------------------------------------------------------------
5/13 PLS-00103: Encountered the symbol "PRC_EXAMEN_SUELDO" when expecting one of the following:
:= . ( # % ; immediate
The symbol ":=" was substituted for "PRC_EXAMEN_SUELDO" to continue.
Errors: check compiler log
I'm using the HR schema of Oracle.
The purpose of the procedure is to check if the day sent is equal to the day of sysdate. If it is, it activates the error.
Supposedly, after compiling this line of code:
set serveroutput on;
update employees set salary = salary + 100 where employee_id = 100;
The trigger should check if according to the sysdate, the change can be done. Else, it throws the specified error.
The stored procedure works properly, but the trigger doesn't. Any help would be appreciated.
EXECUTE is a SQL*Plus command (Docs) for executing stored procedures, ad hoc
set serveroutput on
exec hello -- hello is a procedure that simply dbms_output 'hello' back
Running this in SQL Developer as a script, or in an interactive shell like SQL*Plus or SQLcl, I get
hello
PL/SQL procedure successfully completed.
But these clients have a command interpreter that deals with 'exec' which is short for EXECUTE. It's not part of the PL/SQL language though.
In your trigger body, you'd simply do:
CREATE OR REPLACE TRIGGER TRG_EXAMEN_SUELDO
BEFORE UPDATE OF SALARY ON EMPLOYEES
FOR EACH ROW
DECLARE
HOY VARCHAR(50);
BEGIN
HOY:= TO_CHAR (SYSDATE, 'DAY');
PRC_EXAMEN_SUELDO (HOY);
END;
I have a package specification with record and table types declaration as follows:
CREATE OR REPLACE PACKAGE PCF_USER.PC_PATIO_PLACA_LTQ2 AS
TYPE TY_RECORD_PRODUTO IS RECORD (
CD_PRODUTO PCF_USER.TB_PRODUTOS.CD_PRODUTO%TYPE,
CD_PRODUTO_ORIGEM PCF_USER.TB_PRODUTOS.CD_PRODUTO%TYPE,
CD_EQUIPAMENTO PCF_USER.TB_EQUIPAMENTOS.CD_EQUIPAEMTNO%TYPE,
CD_EQUIPAMENTO_ORIGEM PCF_USER.TB_EQUIPAMENTOS.CD_EQUIPAEMTNO%TYPE
);
TYPE TY_TB_PRODUTO_AUX IS TABLE OF TY_RECORD_PRODUTO
INDEX BY BINARY_INTEGER;
PROCEDURE SP_IN_TRACKING;
END PC_PATIO_PLACA_LTQ2;
And the package body like this:
CREATE OR REPLACE PACKAGE BODY PCF_USER.PC_PATIO_PLACA_LTQ2 AS
PROCEDURE SP_IN_TRACKING IS
vTb_Produto_Aux PCF_USER.PC_PATIO_PLACA_LTQ2.TY_TB_PRODUTO_AUX;
BEGIN
-- insere na tabela auxiliar
INSERT INTO vTb_Produto_Aux (
CD_PRODUTO,
CD_PRODUTO_ORIGEM,
CD_EQUIPAMENTO,
CD_EQUIPAMENTO_ORIGEM)
SELECT DISTINCT
T.ID_SLAB,
T.CD_HEAT,
'PATIO_PLACA_LTQ2',
'FORNECEDOR'
FROM PCF_USER.TB_PATIO_PLACA_LTQ2_TEMP T;
END;
END PC_PATIO_PLACA_LTQ2;
I need to insert values into vTb_Produto_Aux table variable from a select clause.
I'm getting this error when compiling a package body:
[Error] ORA-00942 (25: 17): PL/SQL: ORA-00942: a tabela ou view não
existe
What's wrong with this code? vTb_Produto_Aux is already declared ...
We cannot INSERT INTO a collection in Oracle, you may use BULK COLLECT INTO
SELECT DISTINCT
T.ID_SLAB
,T.CD_HEAT
,'PATIO_PLACA_LTQ2'
,'FORNECEDOR'
BULK COLLECT
INTO vTb_Produto_Aux
FROM PCF_USER.TB_PATIO_PLACA_LTQ2_TEMP T
I am trying to create this stored procedure which should take customer no and email address as input. Then update the email address for that customer. if new email address is same as old then exception should be raised.
CREATE OR REPLACE PROCEDURE UpdateEmail
(CUSTOMERID IN CUSTOMER.CUSTOMERNO%TYPE,
N_EMAIL IN CUSTOMER.EMAIL%TYPE)
IS
DECLARE
e_same EXCEPTION;
V_ROWCOUNT NUMBER;
BEGIN
SELECT COUNT(EMAIL)
INTO V_ROWCOUNT
FROM CUSTOMER#FIT5148B
WHERE CUSTOMER.EMAIL = N_EMAIL
AND CUSTOMER.CUSTOMERNO = CUSTOMERID;
IF V_ROWCOUNT > 0
THEN RAISE e_same;
ELSE
UPDATE CUSTOMER
SET EMAIL = N_EMAIL
WHERE CUSTOMER.CUSTOMERNO = CUSTOMERID;
END IF;
EXCEPTION
WHEN e_same THEN dbms_output.put_line ('email address exist');
END;
/
But it is throwing error. Not sure if I am doing it right. I am using the latest Oracle SQL Developer.
Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting
one of the following: begin function pragma procedure subtype type
current
cursor delete exists prior external language The symbol "begin" was
substituted for "DECLARE" to continue.
Error(28,4): PLS-00103:
Encountered the symbol "end-of-file" when expecting one of the
following: ( begin case declare end exception exit for goto if
loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open
rollback savepoint set sql execute commit forall merge pipe purge
Remove DECLARE .
You should not use Declare in a Procedure. If you are writing a PLSQL block then only you should use Declare. Not in an actual Procedure body.
I am working on an overloaded package and was wondering 2 things.
1) Is there a way to get more info on what error occurred, like what line number it occurred on, as Failed to resolve object details seams a bit vague.
2) What appears to be wrong with this statement?
CREATE OR REPLACE PACKAGE shop_query_pkg IS
procedure shop_info
(p_id IN bb_shopper.idshopper%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
procedure shop_info
(p_id IN bb_shopper.lastname%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
END;
/
CREATE OR REPLACE PACKAGE BODY show_query_pkg IS
procedure shop_info
(p_id IN bb_shopper.idshopper%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
IS
BEGIN
SELECT firstname
into p_firstname
FROM bb_shopper
WHERE idshopper = p_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('ID does not exist');
END;
-- second procedure
procedure shop_info
(p_id IN bb_shopper.lastname%TYPE,
p_firstname out bb_shopper.firstname%TYPE);
IS
BEGIN
SELECT firstname
into p_firstname
FROM bb_shopper
WHERE lastname = p_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Last name does not exist');
END;
END;
/
show errors;
The error
PACKAGE shop_query_pkg compiled
PACKAGE BODY show_query_pkg compiled
Warning: execution completed with warning
Failed to resolve object details
you cannot use the same name and same number of parameters of same type in the overloaded procedure
and also there the package body name is wrong
and other little mistakes are there
Additionally the first and second procedure
the parameter p_firstname types p_firstname out bb_shopper.firstname%TYPE and bb_shopper.firstname%TYPE are both of type Characters(EITHER BOTH CHAR or BOTH VARCHAR2 etc)
and hence doesn't count as different types
Please use the below
CREATE OR REPLACE PACKAGE shop_query_pkg IS
procedure shop_info(p_id1 IN bb_shopper.idshopper%TYPE,
p_firstname1 out bb_shopper.firstname%TYPE);
procedure shop_info(p_id2 IN bb_shopper.lastname%TYPE,
p_firstname2 out bb_shopper.firstname%TYPE);
END;
/
CREATE OR REPLACE PACKAGE BODY shop_query_pkg IS
procedure shop_info(p_id1 IN bb_shopper.idshopper%TYPE,
p_firstname1 out bb_shopper.firstname%TYPE)
IS
BEGIN
SELECT firstname into p_firstname1 FROM bb_shopper WHERE idshopper = p_id1;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('ID does not exist');
END; -- second procedure
procedure shop_info(p_id2 IN bb_shopper.lastname%TYPE,
p_firstname2 out bb_shopper.firstname%TYPE)
IS
BEGIN
SELECT firstname into p_firstname2 FROM bb_shopper WHERE lastname = p_id2;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('Last name does not exist');
END;
END;
/
show errors;
Create a package in different schema from APPS and do not create synonym in APPS.
If the package is having some error while compiling, if you are trying to view the error message using 'show error' it will show message as 'Failed to resolve object details' because the package or synonym is not available in APPS schema.
Check to see if the package spec of the package which you are trying to compile is valid of not. I would suggest you to compile the package spec once again and then compile the package body. This has resolved the issue for me.