2015-12-21 41 views
0

選擇,所以我有以下導致錯誤(對於那些有興趣的:ORA-00904:「的Bleh」:無效的標識符)樣本查詢從子查詢

select bleh from (
      SELECT MIN(mtb.id) KEEP (DENSE_RANK FIRST ORDER BY mtb.id) "bleh" 
       FROM mytable mtb 
      WHERE mtb.filtered_field_one = 0 
       and mtb.filtered_field_two = 0 
      GROUP BY mtb.foreighn_id, mtb.id 
); 

如果我把它變成(注一與*)取代bleh

select * from (
      SELECT MIN(mtb.id) KEEP (DENSE_RANK FIRST ORDER BY mtb.id) "bleh" 
       FROM mytable mtb 
      WHERE mtb.filtered_field_one = 0 
       and mtb.filtered_field_two = 0 
      GROUP BY mtb.foreighn_id, mtb.id 
); 

我得到的結果完全按照我期望的那樣從1日查詢,它看起來像命名的Bleh以恰當的值1列。

那麼爲什麼我不能選擇該列的名稱(別名)?

回答

4

當您用"雙引號將名稱命名爲列時,數據庫需要按原樣調用它,同時還使用雙引號!因此,嘗試這樣的:即使我說as is我認爲,@Stawros提供的評論是一個有價值的信息和平

select bleh from (
     SELECT MIN(mtb.id) KEEP (DENSE_RANK FIRST ORDER BY mtb.id) bleh 
      FROM mytable mtb 
     WHERE mtb.filtered_field_one = 0 
      and mtb.filtered_field_two = 0 
     GROUP BY mtb.foreighn_id, mtb.id 
); 

至於

select "bleh" from (
     SELECT MIN(mtb.id) KEEP (DENSE_RANK FIRST ORDER BY mtb.id) "bleh" 
      FROM mytable mtb 
     WHERE mtb.filtered_field_one = 0 
      and mtb.filtered_field_two = 0 
     GROUP BY mtb.foreighn_id, mtb.id 
); 

還是這樣列命名在Oracle:

bleh = BLEH = Bleh 
but 
"bleh" <> "BLEH" <> "Bleh" 
+3

和'bleh' ='bLEH' ='bleh',但' 「的Bleh」'<>' 「的Bleh」'<>' 「的Bleh」' – Stawros

+1

@Stawros你是絕對正確的!這就是爲什麼我說'原樣':) –

+0

@JorgeCampos我其實知道...當...好男人,謝謝:) –