語義上是按書寫的從前到後順序匹配的。參考SQL 2006標準的Part 2: Foundation (SQL/Foundation)的6.11 <case expression>:
2) Case:a) If the value of the <search condition> of some <searched when clause> in a <case specification> is True, then the value of the <case specification> is the value of the <result> of the first (leftmost) <searched when clause> whose <search condition> evaluates to True, cast as the declared type of the <case specification>.b) If no <search condition> in a <case specification> evaluates to True, then the value of the <case expression> is the value of the <result> of the explicit or implicit <else clause>, cast as the declared type of the <case specification>.
語義上是按書寫的從前到後順序匹配的。參考SQL 2006標準的Part 2: Foundation (SQL/Foundation)的6.11 <case expression>:
2) Case:a) If the value of the <search condition> of some <searched when clause> in a <case specification> is True, then the value of the <case specification> is the value of the <result> of the first (leftmost) <searched when clause> whose <search condition> evaluates to True, cast as the declared type of the <case specification>.b) If no <search condition> in a <case specification> evaluates to True, then the value of the <case expression> is the value of the <result> of the explicit or implicit <else clause>, cast as the declared type of the <case specification>.當然最佳化器有可能可以嘗試分析when的條件是否互斥,如果互斥而且無副作用的話可以任意調整順序,不過表面上展現的語義仍然跟從前到後順序匹配是一樣的。所以從使用的角度看就只認順序匹配就對了。