WHERE column1 comparison_operators constant AND column1 = column2
SELECT * FROM emp e, dept d WHERE e.deptno = 20 AND e.deptno = d.deptno;
WHERE column1 comparison_operators column3 AND column1 = column2
SELECT * FROM emp WHERE job = 'CLERK' OR deptno = 10;
SELECT * FROM emp WHERE deptno = 10 UNION ALL SELECT * FROM emp WHERE job = 'CLERK‘ and deptno <> 10;
SELECT * FROM emp WHERE deptno IN (SELECT deptno FROM dept WHERE loc = ‘NEW YORK’) ;
SELECT emp.* FROM emp, dept WHERE emp.deptno = dept.deptno AND dept.loc = ‘NEW YORK’ ;
뷰쿼리 | 뷰를 생성할때 사용한 SELECT 문 dictionary에 저장된 select문 |
---|---|
액세스쿼리 | 이 뷰를 수행하는 SQL문 |
뷰병합(View Merging)법 | 뷰쿼리를 액세스쿼리에 병합해 넣는 방식 |
---|---|
조건절 진입(Predicate pushing)법 | 뷰병합을 할 수 없는 경우를 대상으로 뷰쿼리 내부에 액세스쿼리의 조건절을 진입시키는 방식 |
CREATE VIEW emp_10 (e_no, e_name, job, manager, salary, commission, deptno) AS SELECT empno, ename, job, mgr, sal, comm, deptno FROM emp WEHRE deptno = 10;
SELECT e_no, e_name, salary, deptno FROM emp_10 WHERE salary > 1000000;
SELECT empno, ename, sal, hiredate FROM emp WHERE deptno = 10 AND sal > 1000000;
CREATE VIEW emp_union_view (e_no, e_name, job, mgr, sal, comm, deptno) AS SELECT empno, ename, job, mgr, sal, comm, deptno FROM regular_emp UNION ALL SELECT empno, ename, job, manager, salary, comm, 90 FROM temporary_emp;
SELECT e_no, e_name, mgr, sal FROM emp_union_view WHERE deptno = 20;
SELECT empno, ename, mgr, sal FROM ( SELECT empno, ename, mgr, sal FROM regular_emp WHERE deptno = 20 UNION ALL SELECT empno, ename, manager, salary FROM temporary_emp WHERE 90 = 20 );
CREATE VIEW emp_group_by_deptno AS SELECT deptno, AVG(sal) avg_sal, MIN(sal) min_sal, MAX(sal) max_sal FROM emp GROUP BY deptno;
SELECT * FROM emp_group_by_deptno WHERE deptno = 10;
SELECT deptno, AVG(sal) avg_sal, MIN(sal) min_sal,MAX(sal) max_sal FROM emp WHERE deptno = 10 GROUP BY deptno;
SELECT d.loc,v.avg_sal FROM dept d, emp_group_by_deptno v WHERE d.deptno = v.deptno AND d.loc = 'London';
SELECT dept.loc, AVG(sal) FROM dept, emp WHERE dept.deprtno = emp.deptno AND dept.loc = 'London' GROUP BY dept.rowid, dept.loc;
SORT (GROUP BY) NESTED LOOPS TABLE ACCESS (FULL) OF 'EMP' TABLE ACCESS (BY INDEX ROWID) OF 'DEPT' INDEX (RANGE SCAN) OF 'PK_DEPT'(UNIQUE)
SELECT /*+ NO_MERGE(v) */ d.loc,v.avg_sal FROM dept d, emp_group_by_deptno v WHERE d.deptno = v.deptno AND d.loc = 'London';
SELECT d.loc, v.avg_sal FROM (SELECT deptno, AVG(sal) avg_sal, MIN(sal) min_sal, MAX(sal) max_sal FROM emp GROUP BY deptno) v, dept d WHERE d.deptno = v.deptno AND d.loc = 'London' ;
HASH JOIN TABLE ACCESS (FULL) OF 'DEPT' VIEW OF 'EMP_GROUP_BY_DEPTNO' SORT (GROUP BY) TABLE ACCESS (FULL) OF 'EMP'
CREATE VIEW emp_group_by_deptno AS SELECT deptno, AVG(sal) avg_sal, MIN(sal) min_sal, MAX(sal) max_sal FROM emp GROUP BY deptno;
SELECT e.ename, e.sal FROM emp e, dept d WHERE (e.deptno, e.sal ) IN (SELECT deptno, avg_sal FROM emp_group_by_deptno) AND e.deptno = d.deptno AND d.loc = 'London' ;
FILTER SORT (GROUP BY) HASH JOIN TABLE ACCESS (FULL) OF 'EMP' TABLE ACCESS (FULL) OF 'EMP'
HASH JOIN TABLE ACCESS (FULL) OF 'EMP' VIEW SORT (GROUP BY) TABLE ACCESS (FULL) OF 'EMP'
SELECT name FROM patients WHERE sex = :input_sex_value ;
WHERE sex =‘M’;
WHERE sex =‘F’;
* <color red>한가지 별도로 쿼리의 실행계획을 확인했을때와 실제로 수행된 실행계획은 다를 수 있다.</color>