Oracle SQL: Sampling a large number of rows from a table -


i want extract roughly 5 million row sample table contain somewhere between 10 million , 20 million rows.

due large number of rows, efficiency key. such, trying avoid sorting rows possible, hence why avoiding dbms_random.value solution have seen in similar questions.

i tried following:

select    *      full_table sample    (ceil(100 * 5000000 / (select count(*) full_table))); 

however, can't seem arithmetic in sample clause (ora-00933: sql command not ended - tried simple sample(10/2) , still same thing).

is reasonable approach, and, if so, how calculate number of rows in sample clause?

you use pl/sql dynamic sql this:

declare   cnt integer; begin   select count(*) cnt full_table;   dbms_output.put_line(cnt);   execute immediate     'insert target_table'     ||' select * full_tablesample (' || ceil(100 * 5000000/cnt) || ')'; end; 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -