Home  >  Article  >  Database  >  Oracle中sign函数和decode函数的使用

Oracle中sign函数和decode函数的使用

WBOY
WBOYOriginal
2016-06-07 17:32:252441browse

在逻辑编程中,经常用到If ndash; Then ndash;Else 进行逻辑判断。在DECODE的语法中,实际上就是这样的逻辑处理过程。它的语法

1.比较大小函数SIGN

sign(x)或者Sign(x)叫做符号函数,其功能是取某个数的符号(正或负):
当x>0,sign(x)=1;
当x=0,sign(x)=0;
当xx可以是函数或计算表达式
 
2.流程控制函数DECODE

在逻辑编程中,经常用到If – Then –Else 进行逻辑判断。在DECODE的语法中,实际上就是这样的逻辑处理过程。它的语法如下:
DECODE(value, if1, then1, if2,then2, if3,then3, . . . else )
Value 代表某个表的任何类型的任意列或一个通过计算所得的任何结果。当每个value值被测试,,如果value的值为if1,Decode 函数的结果是then1;如果value等于if2,Decode函数结果是then2;等等。事实上,可以给出多个if/then 配对。如果value结果不等于给出的任何配对时,Decode 结果就返回else 。 这里的if、then及else 都可以是函数或计算表达式。

相关阅读:

Oracle数据库中的函数,包和触发器

Oracle中窗口函数over()的学习

Oracle数据库生成随机数的函数

Oracle自定义函数查询数据字典项

Oracle日期函数/字符函数/数字函数/转换函数/聚合函数

Oracle中Decode()函数使用说明

 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn