-1
CREATE OR REPLACE FUNCTION totalPatients
RETURN number IS
   total number(2) := 0;
BEGIN
   SELECT count(*) into total
   FROM patient;

   RETURN total;
END;

DECLARE
   c number(2);
BEGIN
   c := totalPatients();
   dbms_output.put_line('Total no. of Patients: ' || c);
END;


Error(11,1): PLS-00103: Encountered the symbol "DECLARE"
  • Possible duplicate of [create oracle package encountered PLS-00103: Encountered the symbol "CREATE"](http://stackoverflow.com/questions/9231788/create-oracle-package-encountered-pls-00103-encountered-the-symbol-create) – user272735 Dec 02 '16 at 04:28
  • This question has nothing to do with [`error-handling`](http://stackoverflow.com/tags/error-handling/info). It is about how to use the tools you have, in this case to write one script that does two things. – William Robertson Dec 02 '16 at 11:46

1 Answers1

2

Add a slash / by itself (on a separate line) after the function definition and after the anonymous block. Everything else should work.

  • 2
    @AasthaGhai - You know better than that. "Still not working" is not enough information. Does it give you the same error? A different one? If a different one, what? –  Dec 02 '16 at 03:27
  • 2
    @AasthaGhai - to be more explicit: I tried **exactly** your code, I changed only the table and column names since I don't have your tables (I used an Employees table from a standard schema); the only change I needed to make was to add the slashes, the function compiled OK, the procedure compiled OK and it gave me the correct count of employees. So "it is still not working" is not very helpful. –  Dec 02 '16 at 03:28