Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting data from CTE's into existing table

766307May 17 2010 — edited May 17 2010
Hello,

I don't understand what is wrong with following query, when I search on the net I find simular sql statements .... my cte works (tested seperately), I've used the for loop just to copy from one table to another ... but when I combine them it goes wrong...

The code that is in commet are some variations I have tried.
            with x as (
              select  
                p.id as id, p.naam as pers , c.id as comp, cp.sectorid as sect
                from competentiepersoon cp
                    join persoon p on p.id = cp.persoonid
                    join competentie c on c.id = cp.competentieid
                    where sectorid = 14 --c1.id
            ), 
            y as (    
                select t1.comp as comp1, t2.comp as comp2, t1.sect, count(*) as tel
                    from x t1, x t2 
                    where t1.comp != t2.comp 
                      and t1.id = t2.id
                    group by t1.comp, t2.comp, t1.sect
            ), 
            z as (
                  select 
                    comp1, comp2, sect, tel / (select count(*) from y  where comp1 = y1.comp1 or comp2 = y1.comp1 or comp1 = y1.comp2 or comp2=y1.comp2 ) as match
                  from y y1 
           )  
          --insert INTO competentiematching(competentieid1, competentieid2, sectorid, matching) 
         --values select comp1, comp2, sect, match from z;
       for toInsert in ( select * from z )
          loop
               insert into competentiematching values(toInsert.comp1, toInsert.comp2,toInsert.sect,toInsert.match);
        end loop;  
=> keeps giving "missing select statement"

ps sorry for my english :).
This post has been answered by Frank Kulash on May 17 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2010
Added on May 17 2010
2 comments
3,079 views