BEGIN
EXECUTE IMMEDIATE 'CREATE OR REPLACE VIEW VSTRUCTDIVISIONPARENTS AS
    WITH CTERECURSIVE(FIRSTID, PARENTID, ID) AS (
    SELECT SD.ID AS FIRSTID, SD.PARENTID AS PARENTID, SD.ID AS ID
    FROM  STRUCTDIVISION SD WHERE SD.PARENTID IS NOT NULL
    UNION ALL 
    SELECT R.FIRSTID AS FIRSTID, SDR.PARENTID AS PARENTID, SDR.ID AS ID
    FROM STRUCTDIVISION SDR
    INNER JOIN CTERECURSIVE R ON R.PARENTID = SDR.ID)
    SELECT DISTINCT FIRSTID AS ID, PARENTID AS PARENTID FROM CTERECURSIVE';
END;