2012-06-22 83 views
3

數據庫是Oracle 10.2.0.1.0 - 在Red Hat企業版Linux ES釋放4(Nahant更新8)運行64位這是一個可能的Oracle錯誤還是我錯過了一些東西?

在SQL * Plus下面的代碼完美運行:

var comment_id number 
exec :comment_id := 3052753 
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 = content_item.get_latest_revision(:comment_id); 
/

在這種情況下,它返回2行,從UNION的每個部分返回1。 如果我改變調用content_item.get_latest_revision如下,它打破如下:

var comment_id number 
exec :comment_id := 3052753 
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); 

/

錯誤:

SQL> where r.revision_id = (select content_item.get_latest_revision(:comment_id) from dual) 
               * 
ERROR at line 14: 
ORA-00904: : invalid identifier 

現在,什麼是真正的瘋狂這塊SQL的是,第二個示例以上是只有案例中斷。例如,如果我在上面的示例2中進行查詢,並從工會兩側刪除doc_name字段,則突然再次發生作用。或者如果我刪除utl_raw.cast_to_varchar2位或聯合本身(並分別運行每個部分)。這只是UNION,AND子句和函數調用的精確組合。

有人提出,它可能是錯誤6038461,'與UNION和快速DUAL子查詢SQL錯誤的結果',但我不認爲這是一個很好的選擇。

任何人都有線索是什麼與第二個查詢?

PS我要補充一點,蟾蜍沒有錯誤 - 查詢運行良好......

+0

同意6038461現在看起來不太合適;在[上一個問題](http://stackoverflow.com/q/11155855/266304)中,不清楚它是錯誤還是給出錯誤結果。我很確定它是* a *錯誤,但看不到完全匹配。您可能需要使用Oracle提出服務請求。 –

+0

由於查詢在TOAD中運行良好,因此在黑暗中進行了總計拍攝,您使用的是哪種版本的SQL Plus? –

+1

您正在運行10gR2的未打補丁版本。這是爲什麼? – APC

回答

0

不是AND/WHERE column = (SELECT column....)一個大風扇,整體上它能夠更好地寫AND/WHERE column IN (SELECT column...)。但在你的情況下,它看起來不像子查詢中有多行或多列的可能性。如何關於我們 -

var comment_id number 
exec :comment_id := 3052753 
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 IN (select content_item.get_latest_revision(:comment_id) 
          from dual); 

/

OR

var comment_id number 
exec :comment_id := 3052753 
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 EXISTS (select 'x' 
        from dual 
        where content_item.get_latest_revision(:comment_id) =r.revision_id); 


/
0

我認爲這是行不通的,因爲你有一個空行; SQLPlus討厭它們。

相關問題