CHAR[VARCHAR2] : column > chr(0) [or colum > '']
DATE : column > to_date('19831116','YYYYMMDD')
NUMBER : column >= OR column < 0
IS NOT NULL 조회
Case1>
SQL> WITH not_null_t AS (SELECT 'a' AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT 'b' FROM dual
UNION ALL
SELECT 'o' FROM dual)
SQL> SELECT *
FROM not_null_t
WHERE c1 IS NOT NULL;
c1
--------------
a
b
o
- Case2>
SQL> WITH not_null_t AS (SELECT 'a' AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT 'b' FROM dual
UNION ALL
SELECT 'o' FROM dual)
SQL> SELECT *
FROM not_null_t
--WHERE c1 IS NOT NULL
WHERE c1 > CHR(0); --> 또는 c1 > ''
c1
--------------
a
b
o
IS NOT NULL조회
Case1>
SQL> ALTER SESSION SET nls_date_format = 'YYYY-MM-DD';
SQL> WITH not_null_t AS (SELECT to_date('20110101','YYYYMMDD') AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT to_date('20111111','YYYYMMDD') FROM dual)
SQL> SELECT *
FROM not_null_t
WHERE c1 IS NOT NULL;
C1
-----------------
2011-01-01
2011-11-11
Case2>
SQL> ALTER SESSION SET nls_date_format = 'YYYY-MM-DD';
SQL> WITH not_null_t AS (SELECT to_date('20110101','YYYYMMDD') AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT to_date('20111111','YYYYMMDD') FROM dual)
SQL> SELECT *
FROM not_null_t
--WHERE c1 IS NOT NULL
WHERE c1 > to_date('19000101','YYYYMMDD'); <-- c1컬럼에 존재 할 수 없는 이전 값
C1
-----------------
2011-01-01
2011-11-11
Case1>
SQL> WITH t1 AS (SELECT -1 AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT 1 FROM dual
UNION ALL
SELECT 1.2 FROM dual
UNION ALL
SELECT 0 FROM dual)
SQL> SELECT *
FROM t1
WHERE c1 IS NOT NULL;
c1
-----
-1
1
1.2
0
Case2>
SQL> WITH t1 AS (SELECT -1 AS c1 FROM dual
UNION ALL
SELECT NULL FROM dual
UNION ALL
SELECT 1 FROM dual
UNION ALL
SELECT 1.2 FROM dual
UNION ALL
SELECT 0 FROM dual)
SQL> SELECT *
FROM t1
--WHERE c1 IS NOT NULL;
WHERE c1 >= 0 OR C1 < 0;
c1
-----
-1
1
1.2
0
단일 테이블의 컬럼 비교와 IS NOT NULL
SQL> SELECT *
FROM not_null_t1
WHERE c3 = c3;
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 26 | 494 | 1272 (1)| 00:00:16 |
| 1 | TABLE ACCESS BY INDEX ROWID| NOT_NULL_T1 | 26 | 494 | 1272 (1)| 00:00:16 |
|* 2 | INDEX FULL SCAN | NOT_NULL_T1_IDX_01 | 24656 | | 1228 (1)| 00:00:15 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("C3" IS NOT NULL) <-- c3=c3 은 c3 IS NOT NULL조건을 포함!!
테이블 조인과 IS NOT NULL
SQL> SELECT t1.*
,t2.*
FROM not_null_t1 t1
,not_null_t2 t2
WHERE t1.c3 IS NOT NULL
AND t1.c2 = t2.c2
AND t1.c3 = t2.c3
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 506K| 18M| 1470 (2)| 00:00:18 |
|* 1 | HASH JOIN | | 506K| 18M| 1470 (2)| 00:00:18 |
| 2 | TABLE ACCESS BY INDEX ROWID| NOT_NULL_T1 | 26 | 494 | 1229 (1)| 00:00:15 |
|* 3 | INDEX FULL SCAN | NOT_NULL_T1_IDX_01 | 26 | | 1228 (1)| 00:00:15 |
|* 4 | TABLE ACCESS FULL | NOT_NULL_T2 | 501K| 9310K| 236 (5)| 00:00:03 |
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."C2"="T2"."C2" AND "T1"."C3"="T2"."C3")
3 - filter("T1"."C3" IS NOT NULL)
4 - filter("T2"."C3" IS NOT NULL)
- NOT_NULL_T2.C3에 신규 인덱스 생성
SQL> CREATE INDEX not_null_t2_idx_01 ON not_null_t2 (c3);
- 실행계획
SQL> SELECT t1.*
,t2.*
FROM not_null_t1 t1
,not_null_t2 t2
WHERE t1.c3 > CHR(0)
AND t1.c2 = t2.c2
AND t1.c3 = t2.c3
AND t1.c3 > CHR(0);
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 109 | 4142 | 7 (15)| 00:00:01 |
|* 1 | HASH JOIN | | 109 | 4142 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| NOT_NULL_T1 | 50 | 950 | 4 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | NOT_NULL_T1_IDX_01 | 50 | | 3 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| NOT_NULL_T2 | 50 | 950 | 2 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | NOT_NULL_T2_IDX_01 | 50 | | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."C2"="T2"."C2" AND "T1"."C3"="T2"."C3")
3 - access("T1"."C3">' ' AND "T1"."C3" IS NOT NULL)
5 - access("T2"."C3">' ')