尝试打印输出时出现 pls-00306 错误

Posted

技术标签:

【中文标题】尝试打印输出时出现 pls-00306 错误【英文标题】:pls-00306 error when trying to print output 【发布时间】:2021-04-27 12:58:25 【问题描述】:

此代码块在调用“put_line”时返回错误 pls-00306 错误数量或类型的参数:

SET SERVEROUTPUT ON
DECLARE  
   ch varchar2(16);
   cursor ebs_user_cur 
   is
   select xmlagg(xmlelement("r", ch)).extract('//text()').getstringval() 
from
(
  select distinct first_value(ch) over (partition by lower(ch))  
  from (
    select substr('abcd#efghijklmn#pqrstuvwxyzABC$DEFGHIJK$LMNPQR!STUVWXYZ1!23456789',
        level, 1)  ch
    from dual 
    connect by level <= 59
    order by dbms_random.value
  )
  where rownum <= dbms_random.value(18,18)
);
l_passwd   ebs_user_cur%ROWTYPE;
BEGIN
open ebs_user_cur;
loop
fetch ebs_user_cur into l_passwd;
DBMS_OUTPUT.PUT_LINE(l_passwd);
EXIT WHEN l_passwd%NOTFOUND;
END LOOP;
close ebs_user_cur;
END;

哪里出错了?

谢谢

【问题讨论】:

【参考方案1】:
    您应该在光标中指定列别名 您应该在l_passwd.field_name 中指定准确的字段名称:
SET SERVEROUTPUT ON
DECLARE  
   ch varchar2(16);
   cursor ebs_user_cur 
   is
   select xmlagg(xmlelement("r", ch)).extract('//text()').getstringval() 
    as res -- <<< see here
    from
    (
      select distinct first_value(ch) over (partition by lower(ch))  
      from (
        select substr('abcd#efghijklmn#pqrstuvwxyzABC$DEFGHIJK$LMNPQR!STUVWXYZ1!23456789',
            level, 1)  ch
        from dual 
        connect by level <= 59
        order by dbms_random.value
      )
      where rownum <= dbms_random.value(18,18)
    );
    l_passwd   ebs_user_cur%ROWTYPE;
BEGIN
  open ebs_user_cur;
  loop
    fetch ebs_user_cur into l_passwd;
    DBMS_OUTPUT.PUT_LINE(l_passwd.res); -- <<< .res here
    EXIT WHEN l_passwd%NOTFOUND;
  END LOOP;
  close ebs_user_cur;
END;

【讨论】:

以上是关于尝试打印输出时出现 pls-00306 错误的主要内容,如果未能解决你的问题,请参考以下文章

PLS-00306:错误调用中的参数数量或类型错误

ORA-06550,PLS-00306;向 Oracle 过程插入数据时出错

PLS-00306:函数调用中的参数数量或类型错误

Oracle 存储过程不工作 PLS-00306

PLS-00306:调用“*”时参数的数量或类型错误

PLS-00306:调用“ABCINPUT”时参数的数量或类型错误