An inline view is a SELECT statement in the FROM-clause of another SELECT statement.

In the query below the INLINE VIEW is : (SELECT AVG(salary) avg_salary from employees )

Inline views are commonly used to simplify complex queries by removing join operations and condensing several separate queries into a single query. So, the purpose of INLINE VIEW is to allow data generated by it, to be used in the original SQL statement. In our example above, the INLINE VIEW expression (SELECT AVG(salary) avg_salary from employees ) was given an alias m. The AVG(salary) expression located inside the INLINE VIEW was given an alias avg_salary. Therefore in the original SELECT statement, we used m.avg_salary as a projected column. This column was formed entirely by INLINE VIEW. Remember SELECT statement is processed by Oracle engine after the FROM clause. Therefore, m.avg_salary  didn’t generate any error during the parsing.

Next example proves that data generate by INLINE VIEW can be sued anywhere in the main SQL query. It was used in SELECT, WHERE and ORDER BY clauses.

The Oracle SQL parser parsed the data in the following sequence: FROM, WHERE, SELECT, ORDER BY.

It is always good to remember that first thing gets done by the parser is FROM Clause, followed by WHERE, GROUP BY, HAVING, SELECT and ORDER BY. ORDER BY is always the last, and SELECT is always next to last.


Leave a comment

Your email address will not be published. Required fields are marked *