Re: dynamic insert querry

  • From: Arul Ramachandran <contactarul@xxxxxxxxx>
  • To: bobmetelsky@xxxxxxxxxxx
  • Date: Sat, 19 Mar 2005 09:49:08 -0800

I am not sure if I have understood your problem ... see if this helps ...
-------------------------------------------------------------------
begin
for rec in (select distinct batch_id from source)
loop
  insert into target 
  select * from src 
  where batch_id = rec.batch_id
  and rownum < 1001;
end loop;
end;
/
-------------------------------------------------------------------

-Arul

On Sat, 19 Mar 2005 08:37:24 -0500, Bob Metelsky
<bobmetelsky@xxxxxxxxxxx> wrote:
> All -  I need to build an insert statement for the following condition
> 
> I have a column with batch_ids with counts from 1-500k
> I want  to build an insert statement that will pull n# of rows
> 
> So I want to insert 1000 rows of each batch id (dosnt matter which) I
> just need a sampling of the data
> 
> goal
> insert into table
> select * from source where batch_id = 123 and count(batch_id) between
> max(count(batch_id) )  -1000 ;
> 
> this is what I have so far, its messy and still needs work
> 
> select 'insert into TARGET select * from SOURCE where batch_id =
> '||batch_id|| '
> and count(batch_id) BETWEEN' ,count(batch_id)|| ' AND 100;'
> from SOURCE where rownum <=10 group by batch_id;
> 
> There  must be a more graceful way to do this <g>
> 
> thanks !
> Bob
> 
> --
> "Oracle error messages being what they are, do not
> highlight the correct cause of fault, but will identify
> some other error located close to where the real fault lies."
> 
> --
> //www.freelists.org/webpage/oracle-l
>
--
//www.freelists.org/webpage/oracle-l

Other related posts: