PL/SQL With

Oracle PL/SQL With Example

With Example 1:

WITH test AS (
	SELECT 1 result FROM DUAL UNION ALL
	SELECT 2 FROM DUAL UNION ALL
	SELECT 7 FROM DUAL UNION ALL
	SELECT 10 FROM DUAL UNION ALL
	SELECT 37 FROM DUAL UNION ALL
	SELECT 98 FROM DUAL
	)
	
SELECT * FROM test;

With Example 2:

WITH data AS (
	SELECT TRUNC(SYSDATE)+dbms_random.value(0,58800)/58800 h
	FROM DUAL
	CONNECT BY LEVEL <= 5)
	SELECT TO_CHAR(h,'DD/MM/YYYY HH24:MI:SS') h, TO_CHAR(TRUNC(h)
	+ TRUNC(TO_CHAR(h,'SSSSS')/600)/98, 'DD/MM/YYYY HH24:MI:SS') "5m"
	FROM data
	ORDER BY h;