Peter
Peter

Reputation: 427

Combine 2 functions and 2 procedures into a package

I've currently got 2 functions and 2 procedures that run fine. To achieve what the program is supposed to do, I execute procedure 1 and then procedure 2, which in turn will reference the functions as it executes. I now need to combine everything into a single package with an entry module to run. Each procedure/function has its own variables so I am not sure where to declare everything (whether in the intro or body).

For the purposes of explaining, I have included what I've tried so far (that didn't work). Any help would be appreciated.

CREATE OR REPLACE package myPackage AS

FUNCTION calculateHoliday (p_day in date);

FUNCTION calculateAvg (p_dayname in varchar2, p_timeinterval in number);

PROCEDURE loopHalfHourValues;

PROCEDURE generateForecast;

END myPackage;


PACKAGE BODY entryModule AS

  ...paste entirety of procedures and functions...

END entryModule;

Upvotes: 0

Views: 2581

Answers (3)

the_slk
the_slk

Reputation: 2182

Function has to return something!

/* package specification */
CREATE OR REPLACE PACKAGE myPackage AS

    /* public variables here */
    g_variable_no NUMBER; 
    g_variable_ch VARCHAR2(4000); 

    /* public procedures and functions here */
    FUNCTION  calculateHoliday(p_day IN DATE) RETURN return_type;
    FUNCTION  calculateAvg(p_dayname IN VARCHAR2, p_timeinterval IN NUMBER) RETURN return_type;
    PROCEDURE loopHalfHourValues;
    PROCEDURE generateForecast;

END myPackage;

/* package specification */
CREATE OR REPLACE PACKAGE BODY entryModule AS

    /* private variables here */
    l_variable_no NUMBER; 
    l_variable_ch VARCHAR2(4000); 

    FUNCTION calculateHoliday(p_day IN DATE) RETURN return_type
    AS
        l_return return_type;
    BEGIN
        RETURN return_type;
    END;

    FUNCTION  calculateAvg(p_dayname IN VARCHAR2, p_timeinterval IN NUMBER) RETURN return_type
    AS
        l_return return_type;
    BEGIN
        RETURN return_type;
    END;

    PROCEDURE loopHalfHourValues
    AS
    BEGIN
        NULL;
    END;

    PROCEDURE generateForecast
    AS
    BEGIN
        NULL;
    END;

END entryModule;

Upvotes: 2

Teshte
Teshte

Reputation: 632

CREATE OR REPLACE PACKAGE "myPackage" AS

FUNCTION calculateHoliday (p_day in date);

FUNCTION calculateAvg (p_dayname in varchar2, p_timeinterval in number);

PROCEDURE loopHalfHourValues;

PROCEDURE generateForecast;

PROCEDURE main;

END myPackage;


CREATE OR REPLACE PACKAGE BODY "myPackage" AS

   -- declare global variables

   FUNCTION calculateHoliday (p_day in date)
    ....
   end calculateHoliday;

   FUNCTION calculateAvg (p_dayname in varchar2, p_timeinterval in number)
   ....
   end calculateAvg;

   PROCEDURE loopHalfHourValues is
   ...
   end loopHalfHourValues;

   PROCEDURE generateForecast is
   ...
   end generateForecast;

   PROCEDURE main is
   ...                   -- entry point call the procedures/functionns
   end main ;


END myPackage;

Upvotes: 1

Prashant Srivastava
Prashant Srivastava

Reputation: 1

your package spec and body are different identifiers use same identifiers for package spec and body

create or replace package myPackage AS --- spec

create or replace package Body myPackage AS --- body

make entrymodule a separate package to call or a separate procedure , in this case i dont think it is required.

Upvotes: 0

Related Questions