您的位置:首页 > 编程语言 > PHP开发

what is DECODE function used for?

2009-09-10 10:26 351 查看
  DECODE is used to decode a CHAR or VARCHAR2 or NUMBER into any of several different strings or numbers based on values,That is DECODE does a value-by-value substitution. For every value that is given in the DECODE function it nakes an "if then"check and matches the value. The general format of DECODE function is given below:

 

  DECODE(value.if1,then1,if2,then2,......,else)

 

Let us see this with an example:

 

 Consider a table named A which has following namely:Empname,sex,salary

 

select * from A

 

Gives output as

 

Empname     sex   salary
------------ ---- -------
Priya         F     20000
Sri           F     10000
Sam           M     20000
Raj           M     20000
Sita          F     10000

 

In the above if we give the DECODE function as below namely:

 

Select empname, sex, DECODE(salary,’20000’,’50000’,’70000’) from exforsys;

 

The output of above DECODE function would result as below:

 

Empname     sex     salary
------------ ----   -------
Priya          F     50000
Sri            F     70000
Sam            M     50000
Raj            M     50000
Sita           F     70000

 

 

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐