相信有過oracle程式設計基礎的人都應該接觸過decode這一函式,沒有接觸過的也沒有關係,接下來我簡單的介紹下關於decode函式的用法,首先decode是oracle的乙個內建函式,典型的sql語句如下:
select decode(a,1,'cc',2,'dd') from t;
寫過sql的,上面的語法應該都能看懂,select是sql的查詢語句,select語句中可以用到結構化的函式,上面語句當中"decode(a,1,'cc',2,'dd')" 這部分對於不清楚decode函式用法的人來說可能不太好懂,所以將結構化的decode函式轉換成過程化語句,就很容易懂了,轉換後的語句為:
if a=1 then
'cc'
else if a=2 then
'dd'
end if;
這樣就能很容易的知道decode函式用法,最後再來講解下最上面的那條sql語句:
decode(a,1,'cc',2,'dd') 可以理解成,如果a=1,那麼就輸出cc,否則如果a=2,那麼就輸出dd,而這裡的a是t表的乙個字段。
Oracle 中 decode 函式用法
含 釋 decode 條件,值1,返回值1,值2,返回值2,值n,返回值n,預設值 該函式的含義如下 if 條件 值1 then return 翻譯值1 elsif 條件 值2 then return 翻譯值2 elsif 條件 值n then return 翻譯值n else return 預設值...
Oracle 中 decode 函式用法
含 釋 decode 條件,值1,返回值1,值2,返回值2,值n,返回值n,預設值 該函式的含義如下 if 條件 值1 then return 翻譯值1 elsif 條件 值2 then return 翻譯值2 elsif 條件 值n then return 翻譯值n else return 預設值...
Oracle 中 decode 函式用法
含 釋 decode 條件,值1,返回值1,值2,返回值2,值n,返回值n,預設值 該函式的含義如下 if 條件 值1 then return 翻譯值1 elsif 條件 值2 then return 翻譯值2 elsif 條件 值n then return 翻譯值n else return 預設值...