Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does something like Common Table Expressions exist in PL/SQL?

I recently learned about CTE's in SQL Server and am attempting to use it in PL/SQL. I do not need the recurive benefits of it, however, I would like to use it in lieu of creating a view and to improve query performance. Just looking for some direction on what code may be similar.

like image 342
Matthew Hoenstine Avatar asked Jul 26 '10 13:07

Matthew Hoenstine


People also ask

Does Oracle have common table expression?

The Common Table Expression or CTE SQL feature is available in the following databases: Oracle (as of version 9.2) SQL Server (as of version 2005) MySQL (as of version 8.0)

Is CTE available in Oracle?

CTE ORACLE is a simple query to simplify the different classes of SQL queries as the derived table concept was just not suitable can be defined as a named temporary result set which can only exist within the scope of a single statement (In this case statement here means SELECT and also DML statements like INSERT and ...

What is CTE in Plsql?

A common table expression (CTE) is a named temporary result set that exists within the scope of a single statement and that can be referred to later within that statement, possibly multiple times.


1 Answers

In Oracle this is known as subquery factoring, and it works the same as in SQL Server AFAIK:

with cte as (select * from emp)
select * from cte join dept on dept.deptno = cte.deptno;

See SELECT documentation and search for "factoring".

like image 56
Tony Andrews Avatar answered Oct 01 '22 16:10

Tony Andrews