0

我正在测试一个以 ref cursor 作为 out 参数的过程。但结果显示“无法运行:ORA 01031 Insufficient priveleges

这是我的程序。它非常简单

PROCEDURE pr_plazalist_get(pn_facility_id  IN facility.facilityid%TYPE
                         ,pcur_plaza_info OUT gtcur_plaza_info) IS

   BEGIN
     OPEN pcur_plaza_info FOR
     SELECT p.plazaid      AS plazaid
           ,p.plazanm      AS plazaname
           ,p.plazaacronym AS palazaacronym
       FROM plaza    p
           ,facility f
      WHERE p.facilityid = f.facilityid
        AND f.facilityid = pn_facility_id;

   END pr_plazalist_get;

我在包的规范中声明了类型如下

TYPE gtrec_plaza_info IS RECORD(
   plazaid      plaza.plazaid%TYPE
  ,plazaname    plaza.plazanm%TYPE
  ,plazaacronym plaza.plazaacronym%TYPE);

类型 gtcur_plaza_info 是参考光标返回 gtrec_plaza_info;

这是 utplsql 的测试包体;

CREATE OR REPLACE PACKAGE BODY ut_pkg_utility_interface AS
 PROCEDURE ut_setup AS
 BEGIN
  NULL;
 END ut_setup;

PROCEDURE ut_teardown AS
 BEGIN
  NULL;
END ut_teardown;

 PROCEDURE ut_pr_plazalist_get IS
  l_in_params  utplsql_util.utplsql_params;
  l_out_params utplsql_util.utplsql_params;

   BEGIN
  utplsql_util.reg_in_param(par_pos => 1, par_val => 1, params => l_in_params);

  utplsql_util.reg_out_param(par_pos => 2, par_type => 'REFCURSOR', params =>    l_out_params);

  utassert.eq_refc_query(p_msg_nm        => 'refcursor test '
                        ,proc_name       => 'pkg_utility_interface.pr_plazalist_get'
                        ,params          => l_in_params
                        ,cursor_position => 2
                        ,qry             => 'SELECT plazaid,plazanm,plazaacronym from plaza p, facility f
                      where p.plaza.facilityid=facility.facilityid where facility.facilityid=1 ');
 END ut_pr_plazalist_get;

END ut_pkg_utility_interface;

当我测试它时,它给了我失败 - pkg_utility_interface.UT_PR_PLAZALIST_GET:无法运行 ut_pkg_utility_interface.UT_PR_PLAZALIST_GET:ORA-01031:权限不足。我的代码和测试包在同一个模式中

这是我的测试脚本 Begin utplsql.test('PKG_UTILITY_INTERFACE',samepackage_in => FALSE,recompile_in => false); 结尾; 这就是我的结果。

FFFFFFF AA III LUU RRRRR EEEEEEE FAAILUURRE
FAAILUURRE
FAAILUURRE
FFFF AAILUU RRRRRR EEEE
F AAAAAAA
ILUURRE FAAILUURRE
FAAILUURRE
FAA III LLLLLL UUU RR EEEEEEE。失败:“PKG_UTILITY_INTERFACE”。单个测试用例结果:

失败 - PKG_UTILITY_INTERFACE.UT_PR_PLAZALIST_GET:无法运行 ut_PKG_UTILITY_INTERFACE.UT_PR_PLAZALIST_GET:ORA-01031:权限不足

utPLSQL 错误日志中记录的错误:

没有找到

4

1 回答 1

1

出现“ORA-01031:权限不足”是因为 utPLSQL 需要临时创建表。为此,它使用EXECUTE IMMEDIATE. 为此,用户需要CREATE TABLE直接授予他们权限,而不是通过角色(另请参见https://stackoverflow.com/a/996709)。

使用utplsql_util.reg_in_paramutplsql_util.reg_out_param设置参数时,您需要使用相同的params变量。您要比较的 SELECT 语句中也有一些错字。因此,您的测试包主体应为:

CREATE OR REPLACE PACKAGE BODY ut_pkg_utility_interface AS
 PROCEDURE ut_setup AS
 BEGIN
  NULL;
 END ut_setup;

PROCEDURE ut_teardown AS
 BEGIN
  NULL;
END ut_teardown;

 PROCEDURE ut_pr_plazalist_get IS
  l_params  utplsql_util.utplsql_params;

   BEGIN
  utplsql_util.reg_in_param(par_pos => 1, par_val => 1, params => l_params);

  utplsql_util.reg_out_param(par_pos => 2, par_type => 'REFCURSOR', params =>    l_params);

  utassert.eq_refc_query(p_msg_nm        => 'refcursor test '
                        ,proc_name       => 'pkg_utility_interface.pr_plazalist_get'
                        ,params          => l_params
                        ,cursor_position => 2
                        ,qry             => 'SELECT plazaid,plazanm,plazaacronym from plaza p, facility f
                      where p.facilityid=f.facilityid and f.facilityid=1 ');
 END ut_pr_plazalist_get;

END ut_pkg_utility_interface;

[全面披露:我是 utPLSQL 项目的管理员之一]

于 2013-10-02T00:17:58.213 回答