oracle绑定变量过多,oracle - 在SQL Plus中使用绑定变量并返回多行? - 堆栈内存溢出...

这是一个愚蠢的问题,但我似乎无法解决。 我有一个查询在OCI程序中引起麻烦,因此我想在SQL * Plus中手动运行它以检查是否有任何区别。 这是查询:

select e.label as doc_name,

e.url,

i.item_id,

'multi' as form_type

from cr_items i, cr_extlinks e

where i.parent_id = :comment_id

and e.extlink_id = i.item_id

UNION

select null as doc_name,

utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(r.content, 2000, 1)) as url,

r.item_id,

'single' as form_type

from cr_revisions r

where r.revision_id = ( select content_item.get_latest_revision(:comment_id) from dual);

end;

我想将comment_id绑定到值3052753,所以我做了以下工作:

DECLARE

comment_id number := 3052753;

BEGIN

select e.label ,

e.url,

i.item_id,

'multi'

from cr_items i, cr_extlinks e

where i.parent_id = :comment_id

and e.extlink_id = i.item_id

UNION

select null ,

utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(r.content, 2000, 1)) as url,

r.item_id,

'single'

from cr_revisions r

where r.revision_id = ( select content_item.get_latest_revision(:comment_id) from dual);

END;

/

这给出了这个错误:

ORA-06550: line 4, column 1:

PLS-00428: an INTO clause is expected in this SELECT statement

现在,我已经很不高兴了,因为我不想从根本上更改此查询,但是无论如何我都会努力并提出这个建议(INTO和UNION并不太顺利):

DECLARE

comment_id number := 3052753;

x_label VARCHAR2(50);

x_url VARCHAR2(500);

x_item number;

x_thing VARCHAR2(50);

BEGIN

select label, url, item_id, thing into x_label, x_url, x_item, x_thing from (

select e.label ,

e.url,

i.item_id,

'multi' as thing

from cr_items i, cr_extlinks e

where i.parent_id = :comment_id

and e.extlink_id = i.item_id

UNION

select null ,

utl_raw.cast_to_varchar2(DBMS_LOB.SUBSTR(r.content, 2000, 1)) as url,

r.item_id,

'single' as thing

from cr_revisions r

where r.revision_id = ( select content_item.get_latest_revision(:comment_id) from dual)) ;

END;

/

但是现在,当然,因为我要返回的行多于1行,所以我完全可以预测

ORA-01422: exact fetch returns more than requested number of rows

现在,我可以继续使用游标等了,但是我的小查询越来越偏离它的原始自我了。 我要做的就是检查查询是否以该comment_id值正常运行。 当然,我可以将comment_id硬编码到查询中,并且工作正常。 但是它在OCI中也可以正常工作,因此我将在SQL * PL中重现该问题以及在OCI代码中看到的绑定变量。 但是,为什么要在SQL * Plus中做到这一点却如此艰难呢? 我是否错过了一些显而易见的事情?

数据库是Oracle 10.2.0.1.0-64位在Red Hat Enterprise Linux ES版本4(Nahant Update 8)上运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值