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
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
相关文章推荐
- What is the HINSTANCE passed to CreateWindow and RegisterClass used for?
- What is the $ symbol used for in JavaScript
- Solution for Can’t update table ‘t1′ in stored function/trigger because it is already used by statement which invoked this store
- what is AttributeOverride annotation used for in Hibernate
- A network analyzer is used for
- What is i'm? Chat for charity initiative officially launched!
- warning: the 'gets' function is dangerous and should not be used.的解决办法
- What is the difference between authorized_key and known_host file for SSH
- vue项目中eslint 警告'functionName is defined but never used'
- do{...}while(0)what is it good for?
- create encode function and decode function for using
- The function getUserId must be used with a prefix when a default namespace is not specified 解决办法
- 关于The function equals must be used with a prefix when a default namespace is not specified解决
- What is the Best Multi-Stage Architecture for Object Recognition?(经典文章阅读)
- GMail is great, but what I am really looking for is myKM service!
- FAQ:What support is there for creating custom text editors?
- 关于The function size must be used with a prefix when a default namespace is not specified解决
- 解决linux下非root用户频繁出现Authentication is required to set the network proxy used for downloading packages
- warning: the ‘gets' function is dangerous and should not be used
- warning: the 'gets' function is dangerous and should not be used.的解决办法