处理空值排序

oracle排序的时候默认空值是最大的,如果想要自己规定空值显示的位置,可以使用关键字NULLS FIRST和NULLS LAST。

创建测试用表:

CREATE OR REPLACE VIEW v AS
SELECT 1 AS c FROM DUAL
UNION ALL
SELECT NULL AS c FROM DUAL
UNION ALL
SELECT 3 AS c FROM DUAL;
SELECT * FROM v;

空值在前:

SELECT * FROM v ORDER BY c NULLS FIRST;

空值在后:

SELECT * FROM v ORDER BY c DESC NULLS LAST;

posted on 2015-10-14 11:20  奈何作贼  阅读(322)  评论(0编辑  收藏  举报

导航