Oracle SQL Developer:如何查看引用游标的结果?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1078506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 01:59:41  来源:igfitidea点击:

Oracle SQL Developer: how to view results from a ref cursor?

oracleoracle-sqldeveloper

提问by Mark Harrison

If I have a function which returns a reference cursor for a query, how can I view the result set of this in SQL Developer? Toad has a special tab for viewing the results of a reference cursor, this is the functionality I would like to find.

如果我有一个返回查询引用游标的函数,我如何在 SQL Developer 中查看它的结果集?Toad 有一个用于查看参考光标结果的特殊选项卡,这是我想要找到的功能。

采纳答案by Rob van Laarhoven

Double click the cursor fields in your result record. On the right side there is a "..." icon. Click this and you'll see the contents

双击结果记录中的光标字段。右侧有一个“...”图标。点击这里,你会看到内容

回答by quillbreaker

SET SERVEROUTPUT ON;
VARIABLE X REFCURSOR;
EXEC PROCEDURE_WITH_OUTPUT_SYS_REFCURSOR(:X);
PRINT X;

回答by Ciaran Bruen

Hi I know this was asked a while ago but I've just figured this out and it might help someone else. Not sure if this is exactly what you're looking for but this is how I call a stored proc and view the output in SQL Developer.
In SQL Developer when viewing the proc, right click and choose 'Run' or select Ctrl+F11 to bring up the Run PL/SQL window. This creates a template with the input and output params which you need to modify. To return the results of a sys_refcursor you then need to declare a row type that is exactlyequivalent to the select stmt / sys_refcursor being returned by the proc. Below I declare "type t_row" which matches my output fields, then loop through the returned sys_refcursor. If t_row matches my sys_refcursor then it gets populated with each row of the sys_refcursor:

嗨,我知道这是不久前被问到的,但我刚刚想通了这一点,它可能会帮助其他人。不确定这是否正是您要查找的内容,但这就是我调用存储过程并在 SQL Developer 中查看输出的方式。
在 SQL Developer 中查看过程时,右键单击并选择“运行”或选择 Ctrl+F11 以打开“运行 PL/SQL”窗口。这将创建一个包含您需要修改的输入和输出参数的模板。要返回 sys_refcursor 的结果,您需要声明一个与 proc 返回的 select stmt / sys_refcursor完全等效的行类型。下面我声明了与我的输出字段匹配的“type t_row”,然后循环遍历返回的 sys_refcursor。

DECLARE
  P_CAE_SEC_ID_N NUMBER;
  P_FM_SEC_CODE_C VARCHAR2(200);
  P_PAGE_INDEX NUMBER;
  P_PAGE_SIZE NUMBER;
  v_Return sys_refcursor;
  type t_row is record (CAE_SEC_ID NUMBER,FM_SEC_CODE VARCHAR2(7),rownum number, v_total_count number);
  v_rec t_row;

BEGIN
  P_CAE_SEC_ID_N := NULL;
  P_FM_SEC_CODE_C := NULL;
  P_PAGE_INDEX := 0;
  P_PAGE_SIZE := 25;

  CAE_FOF_SECURITY_PKG.GET_LIST_FOF_SECURITY(
    P_CAE_SEC_ID_N => P_CAE_SEC_ID_N,
    P_FM_SEC_CODE_C => P_FM_SEC_CODE_C,
    P_PAGE_INDEX => P_PAGE_INDEX,
    P_PAGE_SIZE => P_PAGE_SIZE,
    P_FOF_SEC_REFCUR => v_Return
  );
  -- Modify the code to output the variable
  -- DBMS_OUTPUT.PUT_LINE('P_FOF_SEC_REFCUR = ');
  loop
    fetch v_Return into v_rec;
    exit when v_Return%notfound;
    DBMS_OUTPUT.PUT_LINE('sec_id = ' || v_rec.CAE_SEC_ID || 'sec code = ' ||v_rec.FM_SEC_CODE);
  end loop;

END;

回答by user982785

there are no way to display a refcursor in datagrid in sqldeveloper. we can define a refcursor,call SP,then print refcursor,then data will be printed in Script output window in a plane text mode,but not in Query Result window.

无法在 sqldeveloper 中的数据网格中显示引用。我们可以定义一个refcursor,调用SP,然后打印refcursor,然后数据将以平面文本模式打印在脚本输出窗口中,而不是在查询结果窗口中。