2016-11-09 118 views
-3

1.查詢關於NVL和case語句

select case 
     when id is null then name='muthu' 
     end 
from muthu; 

執行這個查詢後,我得到ORA-00905:缺少關鍵字

  • 00000 - 「缺少關鍵字「錯誤。
  • 2.

    select nvl(id,"not found") name from muthu; 
    

    ORA-00904: 「未找到」:無效的標識符

    (Oracle 10g中分貝和SQL顯影劑4.1) 請任何人都讓我知道最新版本的SQL開發人員

    +0

    的問題是關於SQL開發人員的錯誤或最新版本?另外,Oracle [文檔](https://docs.oracle.com/apps/search/search.jsp?category=database&q=&product=)有什麼問題? – Aleksej

    +0

    請向我們展示示例數據以及您想要實現的目標,因爲目前尚不清楚。 –

    +0

    我有兩列id和名稱的表。我想編寫一個查詢來檢查id列的空值,並將相應的名稱更新爲'n/a'。 –

    回答

    0

    Y我們的第一個查詢失敗,因爲布爾表達式不是的值。我認爲你想要:

    select (case when id is null then 'muthu' 
         end) as name 
    from muthu; 
    

    第二次失敗,因爲字符串應該括在單引號中,而不是雙引號。所以這應該是:

    select nvl(id, 'not found') as name 
    from muthu; 
    

    雖然我更喜歡ANSI標準coalesce()到數據庫特定NVL()

    如果id不是一個字符串,那麼你必須將它轉換爲字符串:

    select nvl(cast(id as varchar2(255)), 'not found') as name 
    from muthu; 
    
    +0

    從muthu中選擇nvl(id,'not found')作爲姓名; ORA-01722:無效號碼 01722。00000 - 「無效號碼」 *原因:指定的號碼無效。 *操作:指定一個有效的號碼。 –

    +0

    從muthu中選擇nvl(id,null); 選擇案例 當id爲null時17 else id end from muthu;兩個查詢現在都能正常工作。感謝所有 –

    0

    不知道是什麼問題,我認爲爲什麼?

    第一個查詢 - 我想你想給這個專欄命名name?如果是這樣,在計算或結束無論對列來命名:

    select case when id is null then 'muthu' 
        end as name 
    from muthu; 
    

    第二個 - 字符串應該用單引號包裹,雙引號是列名:

    select nvl(id,'not found') as name 
    from muthu; 
    
    +0

    爲第一個查詢我想驗證id列爲null,你可以讓我知道該怎麼做。我面臨同樣的錯誤。 –

    +0

    和第二個查詢,即使我刪除唉的名字得到相同的錯誤 –

    +0

    從muthu選擇nvl(id,null); 選擇案例 當id爲null時17 else id end from muthu;兩個查詢現在都能正常工作。謝謝大家。 –