Oracle 中Decode函式的用法

2022-01-29 03:00:42 字數 588 閱讀 7308

第一種形式:

decode(條件,值1,返回值1,值2,返回值2,…值n,返回值n,預設值)

實現資料的彙總:

源資料:

彙總後的資料:使用decode函式處理資料後對dname欄位進行彙總。

第二種形式:

decode(欄位或字段的運算,值1,值2,值3);當字段或字段的運算的值等於值1時,該函式返回值2,否則返回值3。

decode函式功能延伸演示:

一、實現資料的彙總:

源資料:

彙總後的資料:使用decode函式處理資料後對dname欄位進行彙總。

二、對資料進行排序

源資料:

排序:排序規則:1、首先按部門名稱排序  2、相同部門名稱的按照loc排序

sign函式的應用

sign函式語法:sign(n);

sign函式說明:取數字n的符號,大於0返回1,小於0返回-1,等於0返回0(n可以是表示式,(n-200))

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