View-uri locale - instrucţiunea with

Cu instrucţiunea with se pot defini view-uri locale (nu se memorează în dicţionar) care se pot utiliza într-o interogare. Această instrucţiune se poate folosi numai începând cu Oracle 9i. Cu astfel de view-uri se poate genera un plan de execuţie optimizat.
Sintaxa:
WITH view_local_1 AS (SELECT ... )
     [, view_local_2 AS (SELECT ... )] ...
SELECT ...(se pot utiliza: view_local_1, view_local_2, ...)

Exemplu:

with 
  v1 as (select sectia,nrmatricol,max(nota) notamax,nrcredite 
         from rezultate where nota>4 group by sectia,nrmatricol,nrcredite
        ),
  v2 as (select sectia,nrmatricol,to_char(sum(notamax*nrcredite)/sum(nrcredite),'99.99') media,
                sum(nrcredite) nrcredite,count(*) nrdisc 
         from v1
         group by sectia,nrmatricol
        )
  select s.sectia,s.nrmatricol,nume,prenume,cnp,media,nrcredite,nrdisc
  from studenti s inner join v2 on s.sectia=v2.sectia and s.nrmatricol=v2.nrmatricol;

Referinţe: