1
我有一個包含表示層次結構的數據的表。從單個「對象」的表中獲取數據的最簡單方法是遞歸查詢。同一張表還存儲與「對象」關聯的「成員變量」。我認爲這將是很高興看到在一個查詢對象的結構以及相關的成員變量,所以我想是這樣的:混合遞歸查詢和光標表達式
cursor object_explorer is
select (level*2) lvl, ob.object_id, lpad(ot1.object_type_name, 2*level + length(ot1.object_type_name), '.') ob_typ_nam
from obj_tab ob, obj_type ot1
, cursor (select lpad(mv.member_var_name, level + length(mv.member_var_name), ' ') var_nam, /*other stuff*/
from obj_type ot2, object_memberVar_value omv, member_variable mv
where mv.member_variable_id = omv.member_variable_id
and ot2.object_type_id = omv.object_type_id
and omv.object_id = ob.object_id)
where ot1.object_type_id = ob.object_type_id
and /*other filtering conditions unrelated to problem at hand*/
start with ob.objecT_id = '1234567980ABC'
connect by nocycle ob.parent_object = prior ob.object_id;
...和Oracle告訴我「遊標表達不準」。
如果我這樣做是爲兩個單獨的光標(通過一個結果循環再利用基於這些結果的其他光標),一切工作正常,所以我不需要單光標的解決方案。
我只是想知道爲什麼我不能使用光標表達式來組合這兩個查詢 - 或者可以我將它們結合起來,我只是錯過了它?
(Oracle版本爲10g)
我不認爲你可以在from子句中使用Cursor表達式。我也不明白你在這裏試圖做什麼。你能舉一個你希望的輸出的例子嗎? – Craig 2010-12-02 21:57:32
@克雷格:你說得對。我不得不將遊標表達式移動到SELECT子句。 – FrustratedWithFormsDesigner 2010-12-03 21:15:08