oracle - 在 oracle 中以多个游标作为输出执行过程
问题描述
如何在 oracle 中执行具有多个游标作为输出的过程。
CREATE OR REPLACE PROCEDURE TC_OWNER.usp_GetGEGAllDataBySecurityID(
p_SecurityID NUMBER,
cur1 OUT sys_refcursor,
cur2 OUT sys_refcursor,
cur3 OUT sys_refcursor,
cur4 OUT sys_refcursor,
cur5 OUT sys_refcursor)
AS
v_EffectiveDate TIMESTAMP(3);
v_CompanyID NUMBER(10);
BEGIN
SELECT MAX(EffectiveStartDate) INTO v_EffectiveDate
FROM tblGEGSecurityDtls
WHERE SecurityId = p_SecurityID AND SYSDATE BETWEEN EffectiveStartDate
and EffectiveEndDate;
SELECT CompanyID INTO v_CompanyID
FROM tblGEGSecurityDtls
WHERE SecurityId = p_SecurityID AND EffectiveStartDate =
v_EffectiveDate;
usp_GetGEGSecurityDtls(p_SecurityID,cur1);
usp_GetGEGRecommendations(p_SecurityID,cur2);
usp_GetGEGCompanyDtls(v_CompanyID,cur3);
usp_GetGEGSectorRegionData(v_CompanyID,null,cur4);
usp_GetGEGCompanyDivisionData(v_CompanyID,null,cur5);
END;
这里以 usp_ 开头的任何内容都表示一个过程。每个过程都返回一个表。
同样可以在 sql 中轻松实现,但我无法在 oracle 中执行此操作。
编辑:根据 vc74 给出的答案,我尝试使用以下代码打印所有五个表,但它抛出错误:
declare
lcur1 sys_refcursor;
lcur2 sys_refcursor;
lcur3 sys_refcursor;
lcur4 sys_refcursor;
lcur5 sys_refcursor;
begin
usp_GetGEGAllDataBySecurityID(
p_SecurityID => 457,
cur1 => lcur1,
cur2 => lcur2,
cur3 => lcur3,
cur4 => lcur4,
cur5 => lcur5
);
end;
print lcur1;
print lcur2;
print lcur3;
print lcur4;
print lcur5;
如何打印输出窗口中的所有表格?
解决方案
在 Oracle 中事情就不那么简单了,您必须显式声明游标。在 Toad 的网格中显示光标。
variable outer_cur1 refcursor
variable outer_cur2 refcursor
variable outer_cur3 refcursor
variable outer_cur4 refcursor
variable outer_cur5 refcursor
declare
inner_cur1 sys_refcursor;
inner_cur2 sys_refcursor;
inner_cur3 sys_refcursor;
inner_cur4 sys_refcursor;
inner_cur5 sys_refcursor;
begin
pkg_cur1s.get(
pnum_scen_id => 671,
pcsr_cur1 => inner_cur1,
pcsr_cur2 => inner_cur2,
pcsr_cur3 => inner_cur3,
pcsr_cur4 => inner_cur4,
pcsr_cur5 => inner_cur5
);
:outer_cur1 := inner_cur1;
:outer_cur2 := inner_cur2;
:outer_cur3 := inner_cur3;
:outer_cur4 := inner_cur4;
:outer_cur5 := inner_cur5;
end;
print outer_cur1
print outer_cur2
print outer_cur3
print outer_cur4
print outer_cur5
推荐阅读
- javascript - 在 Jest 中测试异步代码:done() 未按预期调用
- sql - 在 NULL SQLSERVER 之前按值排序
- c# - 秒表只有 0ms
- javascript - 部分页面加载了ajax。滚动位置问题
- windows-authentication - 是否可以使用 Spring LDAP 进行 Windows(进程)身份验证?
- delphi - Indy 10 IDFTP - 列出文件时出现“读取超时”错误
- ruby-on-rails - 如何使用 RSPEC 集成正确设置或配置自定义 gem
- apache-camel - 如何使用camel-swagger-java和camel-servlet构建war文件
- sql-server - 仅当另一列具有特定值时才恢复对表的更新更改的 SQL 触发器
- netsuite - 有没有办法在用户编辑表单时在选中/取消选中每行登陆成本时禁用/启用上传按钮?