databaseoracle-databasestored-proceduresplsqlpls-00103

PLS-00103 Encountered the symbol "number"


I'm trying to get the exception for negative values for the loan balance, but I got this error.

Errors for PROCEDURE PRC_PAYMENTS:

LINE/COL ERROR


8/11 PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following: := . ( @ % ; The symbol ":=" was substituted for "NUMBER" to continue.

create or replace procedure prc_payments(PLoanId in number,
PPayDate in date default sysdate, PAmount in number) is
Ex_Pay exception;

begin 
    insert into hr.payments (payment_id, loan_id, payment_date, payment_amount) values(seq_payments.nextval, PLoanId, PPayDate, PAmount);
    commit;
    loan_bal number(6);

    select l.loan_balance
    into loan_bal
    from hr.loans l
    where l.loan_id = PLoanId;

    if loan_bal < 0 then 
     raise Ex_Pay;
    end if;

    update hr.loans h       
    set h.loan_balance = (loan_bal - PAmount)
    where h.loan_id = PLoanId;
    commit; 
    exception
    when Ex_Pay then 
        raise_application_error(-20001, 'El abono no puede ser negativo');
end prc_payments;
/
show error


column payment_id format 99
column loan_id format 99
column payment_date format A8
column payment_amount format 9999
set linesize 100
set pagesize 100

select e.employee_id EMP, e.first_name || ' ' || e.last_name, l.loan_id ID_LOAN, p.payment_amount Payments
from hr.employees e, hr.loans l, hr.payments p
where e.employee_id = l.employee_id 
and l.loan_id = p.loan_id;

Solution

  • Wrong place for variable declaration loan_bal number(6); which should be defined before begininstead of 8th row as in the error text.