Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: help with this simple proc?
Daniel Morgan wrote:
> Glen A Stromquist wrote: >
> > CREATE OR REPLACE PROCEDURE populate_emp (num_recs PLS_INTEGER) IS > > BEGIN > DELETE FROM random_emp; > > INSERT INTO random_emp > SELECT last_name,first_name > FROM company_emp > WHERE empno IS NOT NULL -- undoubedly the primary key so how could it > be > null? > AND rownum < num_recs + 1; > > COMMIT; > END; > / > > You missed the "IS" > The declare can not be used > And the &num_emp does not work in a procedure: It is SQL*Plus. > And I have no idea what you think the dbms_random is doing so I omitted > it.. > > Execute as: > > SQL> exec populate_emp(100) > > Oracle tables are heap tables. There is no order or ordering. To try to > randomize the input is just a waste of perfectly good CPU. > -- > Daniel Morgan > http://www.outreach.washington.edu/extinfo/certprog/oad/oad_crs.asp > damorgan_at_x.washington.edu > (replace 'x' with a 'u' to reply)
Thanks Daniel
Actually empno in this case can be null, in the case of a contract employee there is no empno.
The DBMS_RAND I use for getting x number of random "picks" from the employee table. I'm actully trying to create a little applet for our HR people, who from time to time need to pick X random employees from all employees in some cases, and just certain employees in other cases. For example in this case they want to pick X employees from all that enter for spots in the annual company golf tournament, of which over 200 employees want to participate. In other cases they may want to pick just 2 out of the 400 employees for the 2 company season tickets for the next Oilers game etc.
Using:
select * from (select first_name,last_name from emp_table where <<whatever>> order by dbms_random.value) where rownum <= &num_to_pick
will always return me a random list of employees. Rather than have them run the SQL from a prompt or batch file I am trying to set up a simple MSaccess form to populate a table with whatever number of random employees they want. I thought the easiest way to do this is to have a procedure in oracle do the work rather than try to run the sql itself from a pass through query in MSaccess, once the random_emp table is populated they can view it through access and create a simple report or whatever they wish.
I thought I could use the & as a variable for testing, I will likely have to figure out how to pass a user entered number from the access form. Received on Sat May 03 2003 - 16:04:25 CDT