oracle plsql中decode 函式用法

2021-06-26 02:12:16 字數 926 閱讀 4252

在oracle/ plsql的,decode函式有乙個if - then - else語句的功能。

decode函式的語法是:

decode( expression , search , result [, search , result]... [, default] )

expression值進行比較。

search 是對表達相比的價值。

result是返回的值,如果表示式等於搜尋。

default 是可選的。如果沒有找到匹配,解碼將返回預設值。如果省略了預設,然後解碼語句將返回null(如果沒有找到匹配)。

撤消修改

oracle 9i, oracle 10g, oracle 11g

例項

select supplier_name,

decode(supplier_id, 10000, 'ibm',

10001, 'microsoft',

10002, 'hewlett packard',

'gateway') result

from suppliers;

上述解碼的語句與以下的if - then- else語句是等效的:

if supplier_id = 10000 then

result := 'ibm';

elsif supplier_id = 10001 then

result := 'microsoft';

elsif supplier_id = 10002 then

result := 'hewlett packard';

else

result := 'gateway';

end if;

decode函式將乙個接乙個比較每個supplier_id價值。

oracle PL SQL 中變數繫結用法

從oracle的共享池的設計 和oracle推薦的 pl sql 寫法中,可以看出,變數繫結對效能有比較大的影響,那麼,如何在pl sql 中使用變數繫結呢?首先看看不使用變數繫結的用法 declare cursor cur temp id number is select from table a...

Oracle PL SQL 中如何使用Array

因為在pl sql中並沒有陣列,這是我查資料找的範例和自己寫的範例來解釋如何在pl sql中使用陣列。也許很多人已知道,不過就是讓不知道的朋友們了解一下吧。單維陣列 declare type emp ssn array is table of number index by binary integ...

Oracle PL SQL 中如何使用Array

因為在pl sql 中並沒有陣列.這是偶查資料找的範例和自己寫的範例來解釋如何在pl sql 中使用陣列.也許很多人已知道,不過就是讓不知道的朋友們了解一下吧。單維陣列 declare type emp ssn array is table of number index by binary int...