title: Sampling from Oracle, Need exact number of results (Sample Clause)
body: <p>I am trying to pull a random sample of a population from a Peoplesoft Database. The searches online have lead me to think that the Sample Clause of the select statement may be a viable option for us to use, however I am having trouble understanding how the Sample clause determines the number of samples returned. I have looked at the oracle documentation found here:
  <a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2065953" rel="noreferrer">http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2065953</a></p>
  
  <p>But the above reference only talks about the syntax used to create the sample. The reason for my question is I need to understand how the sample percent determines the sample size returned. It seems like it applies a random number to the percent you ask for and then uses a seed number to count every "n" records. Our requirement is that we pull an exact number of samples for example, that they are randomly selected, and that they are representative of the entire table (or at least the grouping of data we choose with filters)</p>
  
  <p>In a population of 10200 items if I need a sample of approximately 100 items, I could use this statement:</p>
  
  <pre><code>SELECT * FROM PS_LEDGER SAMPLE(1) --1 % of my total population
  WHERE DEPTID = '700064' 
  </code></pre>
  
  <p>However, We need to pull an exact number of samples (in this case 100) so I could pick a sample size that almost always returns more than the number I need then trim it down IE</p>
  
  <pre><code>SELECT Count(*) FROM PS_LEDGER SAMPLE(2.5) --this percent must always give &gt; 100 items
  WHERE DEPTID = '700064' and rownum &lt; 101
  </code></pre>
  
  <p>My concern with doing that, is that my sample would not uniformly represent the entire population. For example if the sample function just pulls every N record after it creates its own randomly generated seed, then choosing the rownum &lt; 101 will cut off all of the records chosen from the bottom of the table. What I am looking for is a way to pull out exactly 100 records from the table, which are randomly selected and fairly representative of the entire table. Please help!!</p>