2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > oracle绑定变量过多 oracle - 在SQL Plus中使用绑定变量并返回多行? - 堆栈内存溢出...

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

时间:2023-01-22 06:49:24

相关推荐

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)上运行

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。