--oracel decode
Function: Determine whether the strings are the same
DECODE(value,if1,then1,if2,then2,if3,then3,...,else)
means
IF condition=value 1 THEN
RETURN(value 1)
ELSIF condition=value 2 THEN
RETURN( value 2)
......
ELSIF condition=value n THEN
RETURN(value 3)
ELSE
RE TURN(default)
END IF
--Usage of Oracle trunc() function
/****************Date********************/
1.select trunc (sysdate) from dual --2013-01-06 Today's date is 2013-01-06
2.select trunc(sysdate, 'mm') from dual --2013-01-01 returns the first day of the current month.
3.select trunc(sysdate,'yy') from dual --2013-01-01 returns the first day of the current year
4.select trunc(sysdate,'dd') from dual --2013-01-06 returns the current year month day
5.select trunc(sysdate,'yyyy') from dual --2013-01-01 returns the first day of the current year
6.select trunc(sysdate,'d') from dual --2013-01-06 (Sunday) returns the first day of the current week One day
7.select trunc(sysdate, 'hh') from dual --2013-01-06 17:00:00 The current time is 17:35
8.select trunc(sysdate, 'mi') from dual --2013- 01-06 17:35:00 TRUNC() function has no second precision
/ ***************Number ***************** ***/
/*
TRUNC (number,
num_digits) Number Number to be truncated.
Num_digits Numbers used to specify rounding precision. The default value of Num_digits is 0.
TRUNC() function does not round off when intercepting
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual -- 123.4
12.select trunc(123.458,-1) from dual
--120 13.select trunc(123.458,-4) from dual
--0 14.select trunc(123.458,4) from dual --123.458
15.select trunc( 123) from dual --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120
--Oracle NVL,NVL2 function
NVL( string1, replace_with)
Function: If string1 is NULL, the NVL function returns the value of replace_with, otherwise it returns the value of string1.
string1 and replace_with must be of the same data type, unless the TO_CHAR function is explicitly used.
NVL2 (E1, E2, E3)
Function: If E1 is NULL, the function returns E3, if E1 is not null, returns E2.