重载问题:错误(83,5):PLS-00307:“REPORTEQ”声明太多匹配这个调用

发布于 2024-11-07 05:09:17 字数 3535 浏览 4 评论 0原文

所以我尝试使用重载,但遇到了一些麻烦。我的包有 4 个名称相同但参数类型不同的过程(VARCHAR2、NUMBER、BOOLEAN、DATE)。包头和包体位于我的问题的末尾。

我正在尝试使用这样的包过程:

OPEN bookCountCur;
FETCH bookCountCur INTO how_many;
testutil.reporteq('add procedure, book record count',
  expected_value => '1', actual_value => how_many);
CLOSE bookCountCur;

OPEN copiesCountCur;
FETCH copiesCountCur INTO how_many;
testutil.reporteq('add procedure, book copy record count',
  expected_value => '1', actual_value => how_many);
CLOSE copiesCountCur;

并且我收到此编译错误:

Error(83,5): PLS-00307: too many declarations of 'REPORTEQ' match this call

这是什么意思?


包头:

CREATE OR REPLACE 
PACKAGE TESTUTIL AS 

  /* TODO enter package declarations (types, exceptions, methods etc) here */ 

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN VARCHAR2, actual_value IN VARCHAR2);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN NUMBER, actual_value IN NUMBER);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN BOOLEAN, actual_value IN BOOLEAN);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN DATE, actual_value IN DATE);

END TESTUTIL;

包体:

CREATE OR REPLACE
PACKAGE BODY TESTUTIL AS

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN VARCHAR2, actual_value IN VARCHAR2) AS
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN NUMBER, actual_value IN NUMBER) AS 
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN BOOLEAN, actual_value IN BOOLEAN) 
  AS
    expected_value_tostr VARCHAR2(5);
    actual_value_tostr VARCHAR2(5); 
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      /* Transform TRUE/FALSE to 'TRUE'/'FALSE' */
      IF TRUE = expected_value
      THEN
        expected_value_tostr := 'TRUE';
      ELSE
        expected_value_tostr := 'FALSE';
      END IF;
      IF TRUE = actual_value
      THEN
        actual_value_tostr := 'TRUE';
      ELSE
        actual_value_tostr := 'FALSE';
      END IF;
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value_tostr || '; got ' || actual_value_tostr);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN DATE, actual_value IN DATE) AS
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || TO_CHAR(expected_value, 'YYYY/MM/DD') 
      || '; got ' || TO_CHAR(actual_value, 'YYYY/MM/DD'));
    END IF;
  END reporteq;

END TESTUTIL;

So I am trying to use overloading but I am having some troubles. My package has 4 procedures with the same name but different type of arguments (VARCHAR2, NUMBER, BOOLEAN, DATE). The package header and package body are at the end of my question.

I am trying to use the package procedure like this:

OPEN bookCountCur;
FETCH bookCountCur INTO how_many;
testutil.reporteq('add procedure, book record count',
  expected_value => '1', actual_value => how_many);
CLOSE bookCountCur;

OPEN copiesCountCur;
FETCH copiesCountCur INTO how_many;
testutil.reporteq('add procedure, book copy record count',
  expected_value => '1', actual_value => how_many);
CLOSE copiesCountCur;

And I am getting this compilation error:

Error(83,5): PLS-00307: too many declarations of 'REPORTEQ' match this call

What does it mean?


Package header:

CREATE OR REPLACE 
PACKAGE TESTUTIL AS 

  /* TODO enter package declarations (types, exceptions, methods etc) here */ 

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN VARCHAR2, actual_value IN VARCHAR2);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN NUMBER, actual_value IN NUMBER);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN BOOLEAN, actual_value IN BOOLEAN);

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN DATE, actual_value IN DATE);

END TESTUTIL;

And the package body:

CREATE OR REPLACE
PACKAGE BODY TESTUTIL AS

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN VARCHAR2, actual_value IN VARCHAR2) AS
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN NUMBER, actual_value IN NUMBER) AS 
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value || '; got ' || actual_value);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN BOOLEAN, actual_value IN BOOLEAN) 
  AS
    expected_value_tostr VARCHAR2(5);
    actual_value_tostr VARCHAR2(5); 
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      /* Transform TRUE/FALSE to 'TRUE'/'FALSE' */
      IF TRUE = expected_value
      THEN
        expected_value_tostr := 'TRUE';
      ELSE
        expected_value_tostr := 'FALSE';
      END IF;
      IF TRUE = actual_value
      THEN
        actual_value_tostr := 'TRUE';
      ELSE
        actual_value_tostr := 'FALSE';
      END IF;
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || expected_value_tostr || '; got ' || actual_value_tostr);
    END IF;
  END reporteq;

  PROCEDURE reporteq(description IN VARCHAR2
  , expected_value IN DATE, actual_value IN DATE) AS
  BEGIN
    DBMS_OUTPUT.PUT(description || ': ');

    IF expected_value = actual_value 
    OR expected_value IS NULL AND actual_value IS NULL
    THEN
      DBMS_OUTPUT.PUT_LINE('PASSED');
    ELSE
      DBMS_OUTPUT.PUT_LINE('FAILED. Expected ' || TO_CHAR(expected_value, 'YYYY/MM/DD') 
      || '; got ' || TO_CHAR(actual_value, 'YYYY/MM/DD'));
    END IF;
  END reporteq;

END TESTUTIL;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南城旧梦 2024-11-14 05:09:18

您的 PL/SQL 变量 how_many 是什么类型?它必须是 VARCHAR2,否则预期值必须是 NUMBER。试试这个:

testutil.reporteq('add procedure, book record count',
  expected_value => '1', actual_value => TO_CHAR(how_many));

问题是(假设 how_many 是数字类型)是您没有与 VARCHAR2 和 NUMBER 参数列表匹配的规范。您有 VARCHAR2/VARCHAR2、NUMBER/NUMBER、VARCHAR2/BOOLEAN 和 DATE/DATE。

What type is your PL/SQL variable how_many? It needs to be a VARCHAR2, else expected_value needs to be a NUMBER. Try this:

testutil.reporteq('add procedure, book record count',
  expected_value => '1', actual_value => TO_CHAR(how_many));

The problem is (assuming how_many is a numeric type) is that you don't have a spec that matches a VARCHAR2 and a NUMBER parameter list. You've got VARCHAR2/VARCHAR2, NUMBER/NUMBER, VARCHAR2/BOOLEAN, and DATE/DATE.

清风夜微凉 2024-11-14 05:09:18

'1' 转换为 VARCHAR2 可以解决问题吗?即:

testutil.reporteq('add procedure, book record count',
  expected_value => cast('1' as VARCHAR2), actual_value => how_many);

我认为文字 '1' 可以被视为 VARCHAR2,或 NUMBER,甚至可能是 BOOLEAN< /code> 由 PL/SQL 编译器...

Does casting '1' to VARCHAR2 do the trick? I.e.:

testutil.reporteq('add procedure, book record count',
  expected_value => cast('1' as VARCHAR2), actual_value => how_many);

I think the literal '1' can be seen as a VARCHAR2, or a NUMBER, or maybe even a BOOLEAN by the PL/SQL compiler...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文