Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I nest "WITH" clause in Oracle SQL?

Tags:

sql

oracle

Following query gives me an error:

"ORA-32034: Unsupported use of WITH clause"

 WITH table_B as 
(
    SELECT * FROM (
        WITH table_A AS
            (SELECT 'Akshay' as NAME FROM DUAL)
        SELECT NAME FROM table_A
    ) WHERE NAME LIKE '%Aks%' ---<<< Note a filter here
)
SELECT * from table_B;

Is there a way out? Thanks

like image 903
Akshay Lokur Avatar asked Jan 12 '17 02:01

Akshay Lokur


2 Answers

You should change your query to:

WITH table_a AS
(
    SELECT 'Akshay' as name 
    FROM dual
)
,table_b AS 
(
    SELECT name 
    FROM table_a
    WHERE name LIKE '%Aks%'
)
SELECT * 
FROM table_b;
like image 158
Pham X. Bach Avatar answered Oct 13 '22 08:10

Pham X. Bach


We can use like following:-

WITH 
table_A AS
            (SELECT 'Akshay' as NAME FROM DUAL),
table_B AS
            (SELECT * FROM table_A where NAME like 'Aks%') --<< Adding filter here now
SELECT * FROM table_B;

Cheers!

like image 45
Akshay Lokur Avatar answered Oct 13 '22 06:10

Akshay Lokur