Compilation failed, line 10 (14:27:16)
The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers.
PLS-00103: Encountered the symbol ";" when expecting one of the following: . ( ) * # % & - + / at mod remainder rem with and or group having intersect minus start union where connect || multiset
The symbol ";" was ignored.**
create or replace trigger "PROMOS_T2"
BEFORE insert or update on "PROMOS"
for each row
DECLARE
ma_exp1 EXCEPTION;
ma_exp2 EXCEPTION;
ma_exp3 EXCEPTION;
cap LOGTS.CAPACITE%TYPE;
nbr INTEGER;
begin
SELECT COUNT (*) INTO nbr FROM LOGTS WHERE :NEW."IDLOG"=IDLOG;
SELECT CAPACITE INTO cap FROM LOGTS WHERE :NEW."IDLOG"=IDLOG;
if (exists(SELECT * FROM PROMOS WHERE :NEW."IDPROMO"=IDPROMO;) )THEN
RAISE ma_exp1;
elsif nbr=1 AND cap < :NEW."NBPLACES" THEN
RAISE ma_exp2;
else
RAISE ma_exp3;
end if;
EXCEPTION
WHEN ma_exp1 THEN
RAISE_APPLICATION_ERROR(-20004,'la promos dèja existe');
WHEN ma_exp2 THEN
RAISE_APPLICATION_ERROR(-20005,'PAS DE PLACE');
WHEN ma_exp3 THEN
RAISE_APPLICATION_ERROR(-20006,'IDLOG nexiste pas');
end;
Take a look at the error message, in particular, the parts
Compilation failed, line 10
and
Encountered the symbol ";"
This is line 10:
if (exists(SELECT * FROM PROMOS WHERE :NEW."IDPROMO"=IDPROMO;) )THEN
See the problem?
Your compilation error is being caused by the semicolon in that line. Removing it will help, but your code will still fail to compile, because you can't call EXISTS in PL/SQL outside of SQL. To fix that, see the answers to this question.
Related
I've got a problem with procedure:
create or replace
PROCEDURE SOLVER AS
IS_ACTIVE "Parameter"."Value"%TYPE;
BEGIN
BEGIN
SELECT "Value" INTO IS_ACTIVE from "Parameter" WHERE "Name" = 'ARCHIVER';
EXCEPTION
WHEN OTHERS THEN
IS_ACTIVE:='OFF';
END;
When I try to run it, I gets an Error:
Error report:
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
:= . ( # % ;
The symbol ";" was substituted for "END" to continue.
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
Version 3.2.09
Main Build 09-30
The error message strongly suggests you are getting the error when you call the procedure, not when you create it (and you did refer to 'when I try to run it'); so you are doing this:
begin
solver
end;
/
which generates exactly that error.
If you add a semicolon it will work:
begin
solver;
end;
/
db<>fiddle
create or replace procedure testpga( psize number ) as
begin
declare
TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX BY BINARY_INTEGER;
myarray nAllotmen_tabtyp;
begin
for i in 1.. psize_loop
myarray(i) := to_char(i);`bold`
end loop;
end;
enter code here
end;enter code here
/
LINE/COL ERROR
8/1 PLS-00103: Encountered the symbol "MYARRAY" when expecting one
of the following:
. ( * # % & - + / at loop mod remainder rem
<an exponent (**)> || multiset
The symbol "." was substituted for "MYARRAY" to continue.
8/12 PLS-00103: Encountered the symbol "=" when expecting one of the
following:
. ( * % & - + / at loop mod remainder rem <an exponent (**)>
|| multiset
LINE/COL ERROR
9/1 PLS-00103: Encountered the symbol "END" when expecting one of
the following:
begin function pragma procedure subtype type
current cursor delete
exists prior
create or replace procedure testpga( psize number )
as
TYPE nAllotment_tabtyp IS TABLE OF char(2048) INDEX BY BINARY_INTEGER;
myarray nAllotment_tabtyp;
begin
for i in 1.. psize
loop
myarray(i) := to_char(i); --'bold'
end loop;
end;
I suggest reading the PL/SQL Language Reference which is part of the Oracle database documentation and available online.
I am facing this error:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/11 PLS-00103: Encountered the symbol "IS" when expecting one of the
following:
:= . ( # % ; not null range default character
My package is:
CREATE OR REPLACE PACKAGE BODY EMP_PK AS
PROCEDURE INSERT_TR(EMPNO EMP_20171250.EMPNO%TYPE,ENAME EMP_20171250.ENAME%TYPE,SAL EMP_20171250.SAL%TYPE) IS
INSERT_ERROR EXCEPTION;
CRUSOR C1 IS INSERT INTO EMP_20171250(EMPNO,ENAME,SAL) VALUES(EMPNO,ENAME,SAL);
BEGIN
IF(C1%FOUND) THEN
DBMS_OUTPUT.PUT_LINE('RECORD INSERTED');
ELSE
RAISE INSERT_ERROR;
END IF;
EXCEPTION
WHEN INSERT_ERROR THEN
DBMS_OUTPUT.PUT_LINE('ERROR WHILE RECORD INSERTION');
END INSERT_TR;
END EMP_PK;
it is not CRUSOR but CURSOR
cursor can't contain INSERT statement; it is a SELECT
you are checking whether cursor returned something, but - you never opened it nor fetched from it so it is pretty much useless
insert_error looks like there was an error while inserting a row, but - you are actually raising it if cursor didn't return anything
Basically, you don't need a cursor at all. Such a procedure would do:
PROCEDURE insert_tr (p_empno emp_20171250.empno%TYPE,
p_ename emp_20171250.ename%TYPE,
p_sal emp_20171250.sal%TYPE)
IS
BEGIN
INSERT INTO emp_20171250 (empno, ename, sal)
VALUES (p_empno, p_ename, p_sal);
END insert_tr;
If insert fails, Oracle will raise an exception anyway so - yes, you can handle it/them if you want.
Also, it is good to distinguish parameter names from column names; for example, precede their names with a p_ (as I did).
I'm trying to create a procedure that after finding all the necessary data prints on screen each one of them.
This procedure searches for members, and it receives two parameters, P_CRITERIO if you are looking for a memeber by ID, Last name or national id, and P_SOCIO which has the id, last name or national id.
I tried deleting the Exception part, I didn't get the same error but I still got one that I can't fix
CREATE OR REPLACE PROCEDURE P_CONSULTAR_SOCIOS (P_CRITERIO IN VARCHAR2,P_SOCIO IN VARCHAR2)
IS
V_SENT_SOCIO SOC_SOCIO%rowtype;
V_DEUDA NUMBER;--total dept
V_SALDO NUMBER;--available money
capital_pagado NUMBER;--how much he has paid
capital_a_pagar NUMBER;--how much he has to pay
V_APORTES NUMBER;--total contributions
BEGIN
IF UPPER(P_CRITERIO) = 'ID' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE ID_SOCIO=P_SOCIO;
ELSE IF UPPER(P_CRITERIO) = 'CEDULA' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE CEDULA=P_SOCIO;
ELSE IF UPPER(P_CRITERIO) = 'APELLIDO' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE APELLIDO=P_SOCIO;
END IF;
--available money
SELECT NVL(SALDO_DISPONIBLE,0) INTO V_SALDO
FROM AHO_CUENTA_AHORRO
WHERE ID_SOCIO = V_SENT_SOCIO.ID_SOCIO;
--calculates if he has any loan active and the amount is stored in V_DEUDA
select sum(capital_pagado) into capital_pagado from cre_prestamos where id_sol_cred=V_SENT_SOCIO.ID_SOCIO;
select sum(capital_a_pagar) into capital_a_pagar from cre_prestamos where id_sol_cred=V_SENT_SOCIO.ID_SOCIO and UPPER(estado)='A';
V_DEUDA := (capital_pagado - capital_a_pagar);
--sum of total contributions
select sum(nvl(sdo.monto,0)) into V_APORTES from soc_detalle_obligaciones sdo
join soc_obligaciones o on sdo.id_obligacion = o.id_obligacion
where o.ID_SOCIO=V_SENT_SOCIO.ID_SOCIO and o.tipo_obligacion = 'A';
--prints result
DBMS_OUTPUT.PUT_LINE('| '||V_SENT_SOCIO.ID_SOCIO||' | '||V_SENT_SOCIO.CEDULA||
' | '||V_SENT_SOCIO.NOMBRE_APELLIDO||' | '||' | '||V_SALDO||' | '||V_DEUDA||' | '||
V_APORTES||' |');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(-20032,'El socio no existe');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Ha ocurrido un error');
END P_CONSULTAR_SOCIOS;
/
the errors I'm getting says
42/1 PLS-00103: Encountered the symbol "EXCEPTION" when expecting one
of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
47/23 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
end not pragma final instantiable order overriding static
member constructor map
There are somethings wrong with your code.
To fix the error with the if, you can replace that part of the code with this
IF UPPER(P_CRITERIO) = 'ID' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE ID_SOCIO=P_SOCIO;
ELSIF UPPER(P_CRITERIO) = 'CEDULA' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE CEDULA=P_SOCIO;
ELSIF UPPER(P_CRITERIO) = 'APELLIDO' THEN
SELECT * INTO V_SENT_SOCIO FROM SOC_SOCIO WHERE APELLIDO=P_SOCIO;
END IF;
There is a mistake with your Exceptions.
PUT_LINE Can't take more than one parameter
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('El socio no existe');
That's what I can see so far
PLS-00103: Encountered the symbol exception always indicates a syntax error. So it is easy to solve by looking at the code above the given line number - 42 in this case - and comparing it with the syntax given in the Oracle PL/SQL documentation.
The problem in your case is that your code could be valid but it's not. You have written
IF ...
ELSE IF
Now that is valid syntax when the second IF is nested:
IF ...
ELSE IF ... END IF;
END IF;
In this scenario every standalone IF is matched with an END IF. But you are actually trying to implement a switch. So you have only one END IF. In this case you must use ELSIF instead:
IF ...
ELSIF ...
END IF;
There is another syntax error in the EXCEPTION block. DBMS_OUTPUT.PUT_LINE() takes one parameter, a string. To return a message with user-defined number use RAISE_APPLICATION_ERROR() function.
The WHEN OTHERS branch is just bad practice. There are literally thousands of Oracle error messages, many of which might trip up your procedure. To condense all those to one generic message is unhelpful to anybody trying to diagnose why the program failed. Initially that will be you, so help yourself as well as the people who will maintain it after you. Also it is also better to raise exceptions rather than use DBMS_OUTPUT: messages can be ignored or go un-noticed, exceptions must be handled.
EXCEPTION
WHEN NO_DATA_FOUND THEN
raise_application_error(-20032,'El socio no existe');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Ha ocurrido un error');
raise;
END P_CONSULTAR_SOCIOS;
First off, I'm a relative newbie to PL/SQL so I might be missing something trivial.
Here is a snippet of code that I'm having issues with running -
FOR indx IN 1 .. arr.COUNT
LOOP
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
WHERE (ca.app_city_id = cityid
AND ca.app_plumbing_id = arr(indx))
AND( BITAND(options1,2) = 2
OR BITAND(options1,1) = 1)
GROUP BY ca.cities;
IF tmp_count >=0 THEN
-- We have an affected app so collect metrics
IF plumbings(indx_mv) ='0Ci30000000GsBN' THEN
count_wrigley:= count_wrigley+tmp_count;
END IF;
counter:= counter+tmp_count; --overall count.
tmp_count:=0;
affected_cities:=null;
END IF;
EXCEPTION -- error thrown here !
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP; -- Error thrown here too.
And here is my error trace -
Error report:
ORA-06550: line 64, column 13:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
ORA-06550: line 68, column 11:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
;
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
It's worth noting that the block fails only with the exception handling and compiles successfully otherwise. So my guess is I'm doing something wrong there?
Any help would be greatly appreciated! Thanks
EXCEPTION aligns with BEGIN ... END blocks. There is no BEGIN inside your loop, so there should be no exception either.
It seems the purpose of the exception is to suppress NO_DATA_FOUND errors inside the loop. So to fix this error you need to put a BEGIN / END block in the loop too. (Ah, you have an END just no BEGIN - your code would hurl with the EXCEPTION block).
FOR indx IN 1 .. arr.COUNT
LOOP
BEGIN
SELECT COUNT(*), ca.cities
INTO tmp_count, affected_cities
FROM PDB.utilities ca
....
EXCEPTION
WHEN NO_DATA_FOUND THEN
CONTINUE;
END;
END LOOP;