0

我目前有 2 个功能和 2 个运行良好的程序。为了实现程序应该做的事情,我先执行过程 1,然后执行过程 2,这反过来会在执行时引用函数。我现在需要将所有内容组合到一个带有入口模块的包中才能运行。每个过程/函数都有自己的变量,所以我不确定在哪里声明所有内容(无论是在介绍中还是在正文中)。

为了解释的目的,我已经包括了我迄今为止尝试过的东西(那没有用)。任何帮助,将不胜感激。

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;
4

3 回答 3

1

函数必须返回一些东西!

/* 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;
于 2013-06-07T08:50:40.380 回答
1
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;
于 2013-06-07T07:04:12.927 回答
0

您的包规格和正文是不同的标识符 对包规格和正文使用相同的标识符

创建或替换包 myPackage AS --- 规范

创建或替换包 Body myPackage AS --- body

使 entrymodule 成为一个单独的包来调用或一个单独的过程,在这种情况下,我认为它不是必需的。

于 2013-06-07T06:54:04.427 回答