How to return a CTE as REFCURSOR from an Oracle stored procedure?
Since the CTE is part of the same SQL statement, it should not contain a semicolon.

So, there should be no semicolon on the second line of the third block or the third line of the fourth block.  The fifth block does not have a contiguous SQL statement.