1
votes

I am a beginner in oracle and following is my function definition and invocation part. I am unable to understand the error that I get when I call the function. Please help me rectify my code.

ORA-06550: line 4, column 56: PLS-00103: Encountered the symbol ")" when expecting one of the following: (

create or replace function totalcustomers
RETURN number
IS
total number:=0;
BEGIN
select count(*) into total from customers;
RETURN total;
END;
/

declare sum number;
BEGIN
sum := totalcustomers();
dbms_output.put_line('Total number of customers '||sum);
END;
/
3

3 Answers

1
votes

Do not use sum as a variable which is a reserved keyword in Oracle.

0
votes

Sum is a function, so it's expecting the open paren. Rename the variable.

0
votes

The function invocation part was throwing the mentioned error, because "sum" might be a pre-defined keyword in oracle. Changing the variable as follows helped.

declare x number;
BEGIN
x:=totalcustomers();
dbms_output.put_line(' Total number of customers: '||x);
END;
/

Output : Statement processed. Total number of customers: 6