Oracle
 SQL >> Database >  >> RDS >> Oracle

Usare FETCH FIRST con UNION ALL in Oracle 12.2

Il trucco è semplicemente racchiudere ciascun ramo tra parentesi. Questo funziona dalla 12.2 in poi:

( Select * From tabl1 where Date = '04-MAR-2020' FETCH FIRST 1 ROW ) UNION ALL ( Select * From tabl1 where Date = '05-MAR-2020' FETCH FIRST 1 ROW )

La mia query di test effettiva, per chiunque voglia vederla in azione, era questa:

(select object_name from user_objects where object_type = 'TABLE' order by object_name fetch first 1 row only) UNION ALL (select object_name from user_objects where object_type = 'VIEW' order by object_name fetch first 1 row only);

Sono le parentesi a dire a Oracle che FETCH FIRST si applica a ciascuna singola query anziché al risultato combinato — senza di esse la clausola di limitazione delle righe deve stare alla fine dell'intera istruzione.