在过程中将ref游标作为out参数测试时,UTplsql返回ora -01031权限不足

时间:2013-08-30 18:01:21

标签: oracle unit-testing plsql

我正在测试一个将ref cursor作为out参数的过程。但结果显示“UNABLE TO RUN:ORA 01031 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);

TYPE gtcur_plaza_info是REF CURSOR RETURN 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:权限不足。我的代码和测试包都在同一个模式

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

  

FFFFFFF AA III L U U RRRRR EEEEEEE    F A A I L U U R R E
   F A A I L U U R R E
   F A A I L U U R R E
   FFFF A A L L U U RRRRRR EEEE
   F AAAAAAAA I L U U R R E
   F A A I L U U R R E
   F A A I L U U R R E
   F A A III LLLLLLL UUU R R EEEEEEE   。    失败:“PKG_UTILITY_INTERFACE”   。   个别测试案例结果:

     

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

     

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

     

没有找到

1 个答案:

答案 0 :(得分:1)

由于utPLSQL需要临时创建表,因此导致“ORA-01031:权限不足”。为此,它使用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项目的管理员之一]