oracle - SQL loop inserts -
i have company table list of companies name , company id.
now there value table hold information company reference company id.
i need first list , size of companies , companies insert particular feature information in value table.
this means need have companies having features in value table.
i tried use below sql gives compilation error. loop works without insert.
declare x number(2) ; begin x in (select distinct company_num company comp_in_comp='t') loop insert value (property_num, data_group, num_updates, created_date, created_by, last_updated_date, last_updated_by, value) values ('78', x ,'0', to_date('2015-12-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'admin', to_date('2015-12-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'admin', 'n'); end loop; end;
you don't need loop - use insert-select statement:
insert value (property_num, data_group, num_updates, created_date, created_by, last_updated_date, last_updated_by, value) select distinct '78', company_num, '0', to_date('2015-12-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'admin', to_date('2015-12-17 00:00:00', 'yyyy-mm-dd hh24:mi:ss'), 'admin', 'n' company comp_in_comp='t'
Comments
Post a Comment