在oracle apex中调用程序

时间:2014-05-09 19:36:43

标签: oracle plsql package oracle-apex procedure

我创建了一个包含两个输入的包,如下所示,但是我在测试包时遇到了问题,看它是否有效。我想调用该过程并测试它的输入为1和1000.有人能建议在Oracle Apex中进行测试吗?我不确定我是否以正确的方式在包内生成输出,如果我在程序和包之外测试代码它可以正常工作。在那一刻,我只想在SQL命令中测试它。

封装

CREATE OR REPLACE PACKAGE pl_work_allocation_pkg
IS
  PROCEDURE pl_work_allocation_pp(lv_crime_id       IN  NUMBER,
                                  lv_emp_no         IN  NUMBER,
                                  lv_end_date       OUT DATE,
                                  lv_work_desc      OUT VARCHAR,
                                  lv_police_officer OUT NUMBER,
                                  lv_work_days      OUT NUMBER,
                                  lv_status         OUT VARCHAR);

  FUNCTION GET_WORK_DAYS1(p_work_end_date IN DATE)
    RETURN NUMBER;

  FUNCTION OVERDUE_DAYS1(p_work_end_date IN DATE)
    RETURN VARCHAR;
END;​

包体

CREATE OR REPLACE PACKAGE BODY pl_work_allocation_pkg
IS
  FUNCTION GET_WORK_DAYS1(p_work_end_date IN DATE) RETURN NUMBER
  IS
    lv_work_days NUMBER(5);
    BEGIN
      lv_work_days := ROUND(p_work_end_date - SYSDATE);
      RETURN lv_work_days;
    END get_work_days1;

  FUNCTION OVERDUE_DAYS1(p_work_end_date IN DATE) RETURN VARCHAR
  IS
    lv_status    VARCHAR(10);
    lv_work_days NUMBER(5);
    BEGIN
      lv_work_days := ROUND(p_work_end_date - SYSDATE);
      IF lv_work_days > 1
      THEN lv_status := 'DUE';
      ELSIF lv_work_days < 1
        THEN lv_status := 'OVERDUE';
      END IF;
      RETURN lv_status;
    END overdue_days1;

  PROCEDURE pl_work_allocation_pp(lv_crime_id       IN  NUMBER,
                                  lv_emp_no         IN  NUMBER,
                                  lv_end_date       OUT DATE,
                                  lv_work_desc      OUT VARCHAR,
                                  lv_police_officer OUT NUMBER,
                                  lv_work_days      OUT NUMBER,
                                  lv_status         OUT VARCHAR)
  IS
    BEGIN
      SELECT
        work_desc,
        lead_police_officer,
        work_end_date
      INTO lv_work_desc, lv_police_officer, lv_end_date
      FROM pl_work_allocation
      WHERE s_reported_crime_id = lv_crime_id
            AND d_emp_id = lv_emp_no;
      lv_work_days := GET_WORK_DAYS(lv_end_date);
      lv_status := OVERDUE_DAYS(lv_end_date);

      dbms_output.PUT_LINE(lv_emp_no || ' is ' || lv_status || ' on case no: ' ||
                           lv_crime_id || ' by ' || lv_work_days || '. Report to ' || lv_police_officer ||
                           ' for ' || lv_work_desc || ' details');

    END pl_work_allocation_pp;
END;

1 个答案:

答案 0 :(得分:1)

这听起来像你想要的

DECLARE
  lv_end_date       date;
  -- Guessing at the length.  You'll be better served using anchored
  -- types everywhere
  lv_work_desc      varchar2(100);  
  lv_police_officer number;
  lv_work_days      number;
  lv_staus          varchar2(10);
BEGIN
 PL_WORK_ALLOCATION_PKG.PL_WORK_ALLOCATION_PP(
    <<first parameter>>,
    <<second parameter>>,
    LV_END_DATE,
    LV_WORK_DESC,
    LV_POLICE_OFFICER,
    LV_WORK_DAYS,
    LV_STATUS );
END;

当然,您可能希望对通过呼叫返回的值执行某些操作。