ORA-06553:PLS-801:测试函数返回ROWTYPE时的内部错误[55018]

时间:2019-04-29 17:09:40

标签: oracle plsql

我需要测试Toad中返回ROWTYPE变量的某些函数。当我尝试运行它时,我得到了Internal error

我跑步是

SELECT MYPACKAGE.MyFunction(param1, aram2, param3) FROM DUAL

有没有办法测试返回Toad的ROWTYPE的函数?

2 个答案:

答案 0 :(得分:0)

是的,这是行不通的。在SQL查询中使用函数时,应假定它返回SQL数据类型,而%ROWTYPE是PL / SQL 记录

这可能就是您现在拥有的:

SQL> create or replace function f_test (par_deptno in number)
  2    return dept%rowtype
  3  is
  4    retval dept%rowtype;
  5  begin
  6    select deptno, dname, loc
  7      into retval
  8      from dept
  9      where deptno = par_deptno;
 10    return retval;
 11  end;
 12  /

Function created.

SQL> select f_test(10) From dual;
select f_test(10) From dual
       *
ERROR at line 1:
ORA-06553: PLS-801: internal error [55018]


SQL>

您可能选择的选项是创建(并返回)对象类型。这是一个示例:

SQL> create or replace type dept_type as object
  2    (deptno number,
  3     dname  varchar2(20),
  4     loc    varchar2(20));
  5  /

Type created.

SQL> create or replace function f_test (par_deptno in number)
  2    return dept_type
  3  is
  4    retval dept_type;
  5  begin
  6    select dept_type(deptno, dname, loc)
  7      into retval
  8      from dept
  9      where deptno = par_deptno;
 10    return retval;
 11  end;
 12  /

Function created.

SQL> select f_test(10).dname From dual;

F_TEST(10).DNAME
--------------------
ACCOUNTING

SQL>

答案 1 :(得分:0)

当您只想测试函数时,可以使用匿名PL / SQL块来调用它,并将其结果分配给匹配的rowtype变量,例如:

declare
  l_row mytable%rowtype;
begin
  -- call the function and assign the result to a variable
  l_row := mypackage.myfunction(1, 2, 3);
  -- do something with the result
  dbms_output.put_line(l_row.some_columns);
end;
/

带有演示表格和扩展功能的快速演示:

create table mytable (col1, col2, col3, col4, col5) as
select 1, 2, 3, 'test', sysdate from dual;

create or replace package mypackage as 
  function myfunction (param1 number, param2 number, param3 number)
  return mytable%rowtype;
end mypackage;
/

create or replace package body mypackage as 
  function myfunction (param1 number, param2 number, param3 number)
  return mytable%rowtype is
    l_row mytable%rowtype;
  begin
    select * into l_row
    from mytable
    where col1 = param1
    and col2 = param2
    and col3 = param3;

    return l_row;
  end myfunction;
end mypackage;
/

从SQL调用会得到与现在看到的相同错误:

    select mypackage.myfunction(1, 2, 3) from dual;

    SQL Error: ORA-06553: PLS-801: internal error [55018]

但是有一个块(通过启用了输出的SQL Developer在此处运行):

set serveroutput on

declare
  l_row mytable%rowtype;
begin
  -- call the function and assign the result to a variable
  l_row := mypackage.myfunction(1, 2, 3);
  -- do something with the result
  dbms_output.put_line(l_row.col4 ||':'|| l_row.col5);
end;
/

test:2019-04-29


PL/SQL procedure successfully completed.

db<>fiddle