在 Oracle SQL Developer 中使用引用游标

发布于 2024-08-09 13:16:47 字数 3283 浏览 8 评论 0原文

我正在使用 Oracle SQL Developer,但在查看返回引用游标的包的结果时遇到问题。下面是包定义:

CREATE OR REPLACE package instance.lswkt_chgoff_recov
as
      type rec_type is record
            (
            source_cd                       lswk_tpr.gltrans.tpr_source_cd%TYPE,
            as_of_dt                        lswk_tpr.gltrans.tpr_as_of_dt%TYPE,
            chrg_off_recov                  varchar2(5),
            process_dt                      lswk_tpr.gltrans.dtgltran%TYPE,
            effect_dt                       lswk_tpr.gltrans.dtgltran%TYPE,
            account_nbr                     lswk_tpr.contract.lcontid%TYPE,
            naics_cd                        lswk_tpr.udfdata.sdata%TYPE,
            prod_type                       varchar2(20),
            off_nbr                         lswk_tpr.schedule.sctrcdty%TYPE,
            borrower_nm                     lswk_tpr.customer.scustnm%TYPE,
            tran_type_cd                    lswk_tpr.gltrans.sglcd%TYPE,
            tran_type_desc                  lswk_tpr.gltrans.sglcd%TYPE,
            tran_amt                        lswk_tpr.gltrans.ctranamt%TYPE,
            note_dt                         lswk_tpr.schedule.dtbk%TYPE,
            accru_cd                        number,
            non_accr_cd                     lswk_tpr.schedule.dtlstincsus%TYPE,
            comm_sb_ind                     varchar2(4)
            );

      type cur_type is ref cursor return rec_type;

      procedure sp
            (
            p_as_of_dt              in      date,
            ref_cur                 in out  cur_type
            );
end;
/

我想问题是这可能,如果是的话,我需要做什么。我正在使用 Oracle SQL Developer 1.5.5。谢谢。

Wade

这是我用来调用我的包的代码(由 TOAD 生成):

DECLARE 
  P_AS_OF_DT DATE;
  REF_CUR instance.LSWKT_CHGOFF_RECOV.CUR_TYPE;
  REF_CUR_row REF_CUR%ROWTYPE;

BEGIN 
  P_AS_OF_DT := '31-AUG-2009';

  instance.LSWKT_CHGOFF_RECOV.SP ( P_AS_OF_DT, REF_CUR );

  DBMS_OUTPUT.Put_Line('REF_CUR =');
  IF REF_CUR%ISOPEN THEN
  DBMS_OUTPUT.Put_Line('  SOURCE_CD  AS_OF_DT  CHRG_OFF_RECOV  PROCESS_DT  EFFECT_DT  ACCOUNT_NBR  NAICS_CD  PROD_TYPE  OFF_NBR  BORROWER_NM  TRAN_TYPE_CD  TRAN_TYPE_DESC  TRAN_AMT  NOTE_DT  ACCRU_CD  NON_ACCR_CD  COMM_SB_IND');
    LOOP
      FETCH REF_CUR INTO REF_CUR_row;
      EXIT WHEN REF_CUR%NOTFOUND;
      DBMS_OUTPUT.Put_Line(
           '  ' || '[TPR_SOURCE_CD%type]'
        || '  ' || '[TPR_AS_OF_DT%type]'
        || '  ' || '''' || REF_CUR_row.CHRG_OFF_RECOV || ''''
        || '  ' || '[DTGLTRAN%type]'
        || '  ' || '[DTGLTRAN%type]'
        || '  ' || '[LCONTID%type]'
        || '  ' || '[SDATA%type]'
        || '  ' || '''' || REF_CUR_row.PROD_TYPE || ''''
        || '  ' || '[SCTRCDTY%type]'
        || '  ' || '[SCUSTNM%type]'
        || '  ' || '[SGLCD%type]'
        || '  ' || '[SGLCD%type]'
        || '  ' || '[CTRANAMT%type]'
        || '  ' || '[DTBK%type]'
        || '  ' || NVL(TO_CHAR(REF_CUR_row.ACCRU_CD), 'NULL')
        || '  ' || '[DTLSTINCSUS%type]'
        || '  ' || '''' || REF_CUR_row.COMM_SB_IND || '''');
    END LOOP;
  ELSE
    DBMS_OUTPUT.Put_line('  (Ref Cursor is closed)');
  END IF;


  COMMIT; 
END;

我收到错误:

ORA-06502: PL/SQL: numeric or value error

希望这能更清楚一点。

I am using Oracle SQL Developer, but I am having an issue seeing results from a package that returns a ref cursor. Below is the package definition:

CREATE OR REPLACE package instance.lswkt_chgoff_recov
as
      type rec_type is record
            (
            source_cd                       lswk_tpr.gltrans.tpr_source_cd%TYPE,
            as_of_dt                        lswk_tpr.gltrans.tpr_as_of_dt%TYPE,
            chrg_off_recov                  varchar2(5),
            process_dt                      lswk_tpr.gltrans.dtgltran%TYPE,
            effect_dt                       lswk_tpr.gltrans.dtgltran%TYPE,
            account_nbr                     lswk_tpr.contract.lcontid%TYPE,
            naics_cd                        lswk_tpr.udfdata.sdata%TYPE,
            prod_type                       varchar2(20),
            off_nbr                         lswk_tpr.schedule.sctrcdty%TYPE,
            borrower_nm                     lswk_tpr.customer.scustnm%TYPE,
            tran_type_cd                    lswk_tpr.gltrans.sglcd%TYPE,
            tran_type_desc                  lswk_tpr.gltrans.sglcd%TYPE,
            tran_amt                        lswk_tpr.gltrans.ctranamt%TYPE,
            note_dt                         lswk_tpr.schedule.dtbk%TYPE,
            accru_cd                        number,
            non_accr_cd                     lswk_tpr.schedule.dtlstincsus%TYPE,
            comm_sb_ind                     varchar2(4)
            );

      type cur_type is ref cursor return rec_type;

      procedure sp
            (
            p_as_of_dt              in      date,
            ref_cur                 in out  cur_type
            );
end;
/

I guess the question is this possible and if so, what do I need to do. I am using Oracle SQL Developer 1.5.5. Thanks.

Wade

Here is the code I used to call my package (generated by TOAD):

DECLARE 
  P_AS_OF_DT DATE;
  REF_CUR instance.LSWKT_CHGOFF_RECOV.CUR_TYPE;
  REF_CUR_row REF_CUR%ROWTYPE;

BEGIN 
  P_AS_OF_DT := '31-AUG-2009';

  instance.LSWKT_CHGOFF_RECOV.SP ( P_AS_OF_DT, REF_CUR );

  DBMS_OUTPUT.Put_Line('REF_CUR =');
  IF REF_CUR%ISOPEN THEN
  DBMS_OUTPUT.Put_Line('  SOURCE_CD  AS_OF_DT  CHRG_OFF_RECOV  PROCESS_DT  EFFECT_DT  ACCOUNT_NBR  NAICS_CD  PROD_TYPE  OFF_NBR  BORROWER_NM  TRAN_TYPE_CD  TRAN_TYPE_DESC  TRAN_AMT  NOTE_DT  ACCRU_CD  NON_ACCR_CD  COMM_SB_IND');
    LOOP
      FETCH REF_CUR INTO REF_CUR_row;
      EXIT WHEN REF_CUR%NOTFOUND;
      DBMS_OUTPUT.Put_Line(
           '  ' || '[TPR_SOURCE_CD%type]'
        || '  ' || '[TPR_AS_OF_DT%type]'
        || '  ' || '''' || REF_CUR_row.CHRG_OFF_RECOV || ''''
        || '  ' || '[DTGLTRAN%type]'
        || '  ' || '[DTGLTRAN%type]'
        || '  ' || '[LCONTID%type]'
        || '  ' || '[SDATA%type]'
        || '  ' || '''' || REF_CUR_row.PROD_TYPE || ''''
        || '  ' || '[SCTRCDTY%type]'
        || '  ' || '[SCUSTNM%type]'
        || '  ' || '[SGLCD%type]'
        || '  ' || '[SGLCD%type]'
        || '  ' || '[CTRANAMT%type]'
        || '  ' || '[DTBK%type]'
        || '  ' || NVL(TO_CHAR(REF_CUR_row.ACCRU_CD), 'NULL')
        || '  ' || '[DTLSTINCSUS%type]'
        || '  ' || '''' || REF_CUR_row.COMM_SB_IND || '''');
    END LOOP;
  ELSE
    DBMS_OUTPUT.Put_line('  (Ref Cursor is closed)');
  END IF;


  COMMIT; 
END;

I get the error:

ORA-06502: PL/SQL: numeric or value error

Hope this clears it up a bit more.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

萌无敌 2024-08-16 13:16:47

您可以轻松地在 SQL Developer 中打印 ref_cursor 的输出结果以查看返回值。

以下是 Refcursor 函数的示例:

create or replace function get_employees() return sys_refcursor as
  ret_cursor sys_refcursor;
begin
  open ret_cursor for
    select * from employees;
  return ret_cursor; 
end get_employees;

快速而肮脏的方法:

select get_employees() from dual; 

整洁的方法:

variable v_ref_cursor refcursor;
exec :v_ref_cursor := get_employees(); 
print :v_ref_cursor

You can easily print the output results of a ref_cursor in SQL Developer to see the return value..

Here's an example of a Refcursor Function:

create or replace function get_employees() return sys_refcursor as
  ret_cursor sys_refcursor;
begin
  open ret_cursor for
    select * from employees;
  return ret_cursor; 
end get_employees;

Quick and dirty method:

select get_employees() from dual; 

Neat and tidy method:

variable v_ref_cursor refcursor;
exec :v_ref_cursor := get_employees(); 
print :v_ref_cursor
抽个烟儿 2024-08-16 13:16:47

如果您有一个过程需要在过程签名中使用引用光标,您可以执行以下操作:

var rc refcursor;
execute <package>.my_proc(:rc);
print rc;

突出显示并按 F5。

If you have a procedure which requires a refcursor in the signature of the proc, you can do this:

var rc refcursor;
execute <package>.my_proc(:rc);
print rc;

Highlight and hit F5.

幸福还没到 2024-08-16 13:16:47

我在生成的程序中看到的唯一显式值是

 P_AS_OF_DT := '31-AUG-2009';

尝试显式转换(to_date ('31-AUG-2009', 'DD-MON-YYYY') 相反,也许这会摆脱 如果这

没有帮助,你能看看你的错误是在 sp 中还是在你的代码中生成的吗?如果你不能直接找出这个问题,请从你的代码中定义一个 sp,设置一个断点并执行步骤。通过代码看看错误是从哪里来的。

The only explicit value that I see in the generated program is

 P_AS_OF_DT := '31-AUG-2009';

Try a an explicit conversion (to_date ('31-AUG-2009', 'DD-MON-YYYY') instead, maybe that gets rid of the problem.

If that doesn't help, can you see if your error is generated in the sp or in yor code? If you can't figure this out directly, define an sp from the code you have, set a breakpoint and step through the code to see where the error comes from.

最冷一天 2024-08-16 13:16:47

在您的评论中,您说这是错误:

ORA-06502: PL/SQL: 数字或值
错误 ORA-06512: 在第 16 行

无论有时看起来如何,PL/SQL 错误都不是随机生成的。此错误表明数据类型转换存在缺陷,该转换发生在过程的第 16 行。如果没有看到您的整个过程,我们就不可能精确定位第 16 行。幸运的是,SQL Developer 中的代码编辑器会将行号放在行号中;如果您没有看到行号,则需要切换首选项。

您需要查找的是被转换为数字或日期变量的字符串,或者被转换为日期字段的数字。这可以通过显式的 TO_NUMBER() 或 TO_DATE 来表示,在这种情况下,您需要检查格式掩码和/或数据内容。或者,您可能有隐式强制转换。在这种情况下,您可能需要使用适当的格式掩码使其明确。当然,这可能是意外且不需要的转换,因为 SELECT 语句的投影与 REF CURSOR 记录的签名不匹配。这很容易解决。

In your comment you sayHere is the error:

ORA-06502: PL/SQL: numeric or value
error ORA-06512: at line 16

Whatever it may appear like sometimes, PL/SQL errors are not randomly generated. This error points to a flawed data type conversion which occurs at line 16 of your procedure. Without seeing your whole procedure it is not possible for us to pinpoint line 16. Fortunately the Code Editor in SQL Developer will put line numbers in the gutter; if you are not seeing line numbers you will need to toggle a preference.

What you need to look for is a string being cast to a number or date variable, or a number being cast to a date field. This may be signalled by an explicit TO_NUMBER() or TO_DATE, in which case you need to check the format mask and/or the data content. Alternatively you may have an implicit cast. In that case you may need to make it explicit, with the appropriate format mask. Of course it could be an accidental and unwanted conversion because the projection of the SELECT statement doesn't match the signature of the REF CURSOR record. That is easy to fix.

梦里泪两行 2024-08-16 13:16:47

只需创建一个循环,遍历返回的引用游标即可。您可以使用DBMS_OUTPUT.PUT_LINE()输出到控制台并选择要显示的特定字段。

Just make a loop which iterates through the ref cursor returned. You can output to the console using DBMS_OUTPUT.PUT_LINE() and choosing specific fields to show.

我不在是我 2024-08-16 13:16:47

如果不查看游标的查询是什么,就无法判断。查看在过程 SP 中运行的 SELECT 语句。您选择进入 rec_type 中数字字段的列之一返回字符数据,该数据无法转换为数字。

不要试图弄清楚如何输出游标,而是从 sp 中获取 SELECT 语句并独立运行它。往下看你得到的结果。您将在您期望数字的字段之一中查找返回的一些非数字值。

There's no way to tell without seeing what the cursor's query is. Take a look at the SELECT statement you're running in the procedure SP. One of the column's you are selecting into a numeric field in rec_type is returning character data, which cannot be converted to a number.

Instead of trying to figure out how to output the cursor, take the SELECT statement from sp and run it standalone. Look down the results you get. You're going to be looking for some non-digit values coming back in one of the fields where you expect a number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文