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)上運行
總結
以上是生活随笔為你收集整理的oracle绑定变量过多,oracle - 在SQL Plus中使用绑定变量并返回多行? - 堆栈内存溢出...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蔚小理竞争格局如何?蔚来秦力洪:我们希望
- 下一篇: shell oracle查询数组,she