Question

I'm trying to create a package that works out the number of days between two dates, I'm aware I have probably got this miles wrong, I am really struggling to troubleshoot this. My knownledge is low on oracle, I'm still quite new to this. The package I've written is below, but I am getting the error shown at the bottom.

How do I resolve this?

CREATE OR REPLACE PACKAGE PACKNAME
   AS
   FUNCTION TIME_SCALE RETURN NUMBER;
   END;
/
    CREATE OR REPLACE PACKAGE BODY PACKNAME
   AS   closed_date := '28-APR-14'
   FUNCTION TIME_SCALE RETURN NUMBER;
   IS BEGIN
   TRUNC(mrc.closed_date - mrc.open_date) AS days_difference FROM     TASKS mrc;
   END;

Error at line 2: PLS-00103: Encountered the symbol "=" when expecting one of the     following: constant exception <an identifier> <a double-quoted delimited-identifier> table     long double ref char time timestamp interval date binary national character nchar

I have substituted some of the names to make them clearer for you to read.

The function is to output the number of days it has taken for a task to be completed. The columns basically include the date_opened and date_closed in simple terms as well as a few others and a unique ID which I believe is a sequence.

Was it helpful?

Solution

Try this:

CREATE OR REPLACE PACKAGE PACKNAME
AS
  FUNCTION TIME_SCALE
    RETURN NUMBER;
END;
/
CREATE OR REPLACE PACKAGE BODY PACKNAME
AS
  closed_date VARCHAR2(50):= '28-APR-14';
  days_difference NUMBER;
FUNCTION TIME_SCALE
  RETURN NUMBER
IS
BEGIN
  SELECT TRUNC(mrc.closed_date - mrc.open_date) INTO days_difference
  FROM TASKS mrc;
  RETURN days_difference;
END;
END;

What was wrong:

1) You have missed the type for closed_date
2) You had an ';' after RETURN NUMBER in function declaration
3) You have missed SELECT clause inside function
4) You have missed END for the package

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top