Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> dynamic insert querry
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." -- http://www.freelists.org/webpage/oracle-lReceived on Sat Mar 19 2005 - 08:41:08 CST