一、nvl函数的用法
通过查询获得某个字段的合计值,如果这个值位null将给出一个预设的默认值。
select nvl(sum(t.num),0) from demo t where t.sex='1';
nvl(sum(t.num),0) 的意思就是如果sum(t.num)查询的结果为null,那我们就将sum(t.num)设置默认值为 0.
二、 rpad函数从右边对字符串使用指定的字符进行填充 .
例如:rpad('tech', 8, '0'); 将返回'tech0000'
三、DECODE 函数的用法
DECODE 中的if-then-else逻辑,原理 DECODE(value, if1, then1, if2,then2, if3,then3, . . . else ) 。
例如:decode(X,1,'x=1',2,'x=2' ,'啥都不是')
select decode(X,1,'x=1',2,'x=2' ,'啥都不是') from dual;
如果X为1,则查询结果返回'x=1';
如果X为2,则查询结果返回'x=2';
否则返回 '啥都不是'.
四、 SIGN函数的语法
取数字n的符号,大于0返回1,小于0返回-1,等于0返回0
select sign(100),sign(-100),sign(0) from dual;
分别返回 1 -1 0