【MogDB在ORACLE和MogDB中查看存储过程出参游标数据的方式

一、前言

使用ORACLE作为数据库的应用软件中,偶尔会遇到使用游标作为出参的存储过程,这种存储过程迁移到MogDB并不需要进行改造,但是在开发这样的存储过程时,开发人员偶尔会想要在数据库中测试执行一下,看看游标中的数据是否符合预期,但游标并不是常规的基本数据类型,再写一段plsql或者其他语言的代码去扫游标中的数据打印出来又会有额外的开发量。因此本文介绍几种在开发过程中,ORACLE和MogDB查看出参游标数据的方式。

二、测试对象创建

以下代码在ORACLE和MogDB(A模式)中均可执行

--创建测试表并插入数据 create table t_test_cursor1(col1 number,col2 varchar2(100)); insert into t_test_cursor1 values (1,'abc'); insert into t_test_cursor1 values (1,'def'); commit; --创建带出参游标的package create or replace package pkg_test_mutil_cursor is procedure proc (a int, c1 out sys_refcursor, c2 out sys_refcursor, c3 out sys_refcursor); end; / create or replace package body pkg_test_mutil_cursor is procedure proc (a int, c1 out sys_refcursor, c2 out sys_refcursor, c3 out sys_refcursor) is begin open c1 for select * from t_test_cursor1 where col1=a; open c2 for select col1 ,count(1) ct from t_test_cursor1 where col1=a group by col1; open c3 for select col1,substr(listagg(col2,',') within group(order by col2),1,100) l from t_test_cursor1 where col1=a group by col1; end; end; /