1.nvl( ) 函数 -------oracle
从两个表达式返回一个非 null 值。
语法
NVL(eExpression1, eExpression2)
参数
eExpression1, eExpression2
如果 eExpression1 的计算结果为 null 值,则 NVL( ) 返回 eExpression2。如果 eExpression1 的计算结果不是 null 值,则返回 eExpression1。eExpression1 和 eExpression2 可以是任意一种数据类型。如果 eExpression1 与 eExpression2 的结果皆为 null 值,则 NVL( ) 返回 .NULL.。
返回值类型
字符型、日期型、日期时间型、数值型、货币型、逻辑型或 null 值
说明
在不支持 null 值或 null 值无关紧要的情况下,可以使用 NVL( ) 来移去计算或操作中的 null 值。
select nvl(a.name,'空得') as name from student a join school b on a.ID=b.ID
注意:两个参数得类型要匹配
ISNULL()函数 -----------sql
语法
ISNULL ( check_expression , replacement_value)
参数
check_expression
将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。
replacement_value
在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。
返回类型
返回与 check_expression 相同的类型。
注释
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。
2.sql:select top 10 * from rownum_test rt;
oracle:Rownum和row_number() over()
SELECT * FROM (SELECT a.* FROM torderdetail a ORDER BY order_date DESC) WHERE ROWNUM <= 10
3.
Oracle trunc()函数的用法
/**************日期********************/
1.select trunc(sysdate) from dual --2011-3-18
今天的日期为2011-3-18
2.select trunc(sysdate, 'mm') from dual --2011-3-1
返回当月第一天.
3.select trunc(sysdate,'yy') from dual
--2011-1-1 返回当年第一天
4.select trunc(sysdate,'dd') from dual
--2011-3-18 返回当前年月日
5.select trunc(sysdate,'yyyy') from dual
--2011-1-1 返回当年第一天
6.select trunc(sysdate,'d') from dual
--2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual
--2011-3-18 14:00:00 当前时间为14:41
8.select trunc(sysdate, 'mi') from dual --2011-3-18
14:41:00 TRUNC()函数没有秒的精确
/***************数字********************/
/*
TRUNC(number,num_digits)
Number 需要截尾取整的数字。
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
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
原文出自【比特网】,转载请保留原文链接:http://soft.chinabyte.com/database/27/11420027.shtml