Oracle中decode函式的用法解析

2021-10-17 06:53:48 字數 728 閱讀 1561

該函式的含義如下:

if 條件=值1 then

return(返回值1)

elsif 條件=值2 then

return(返回值2)

......

elsif 條件=值n then

return(返回值n)

else

return(預設值)

end if

這個函式執行的結果是,當字段或字段的運算的值等於值1時,該函式返回值2,否則返回值3,當然值1,值2,值3也可以是表示式,這個函式使得某些sql語句簡單了。

sign()函式根據某個值是0、正數還是負數,分別返回0,1,-1。

示例:

select id,sign(id-2) from table;
執行結果:

在字段id前邊補欄位0且長度為2

select lpad(id,2,0) from table;
執行結果

decode函式的使用場景參考部落格:

sql功底在於平時的積累,後續會持續總結。

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 預設值...