2015-06-03 67 views
2

爲什麼只有第一個工作?案例表達式和布爾值

  1. 回報 '藍色':

    select case when 'a' = 'a' then 'blue' end from dual;

  2. 錯誤:ORA-00920:無效的關係運算符

    select case when true then 'blue' end from dual;

  3. ORA-00904: 「TRUE」:無效標識符

    select case when 'a' = 'a' then true end from dual;

  4. ORA-00905:缺少關鍵字

    select case when 'b' = 'b' then 'a' = 'a' end from dual;

回答

2

有是Oracle SQL沒有一個真正的布爾SQL類型。無論是真還是假常數。布爾值通常用單個字符'Y'或'N'或數字0或1表示。

+1

確實沒有'true'或'false'SQL關鍵字,但是'a'='a''評估爲布爾值,不使用Y/N或0/1。 Oracle'case'表達式是Oracle SQL中使用布爾值(作爲條件而不是結果)的一個地方,類似於where子句的條件。 – GriffeyDog