0

I am trying to create a FOR loop which inserts 1000 employees into the employee table. It's ok if they have the same name but the other 3 values must have different values. I need the emp_id to insert the 1000 employees from 307_1307, have the manager emp_id either 304 or 305(randomly chosen) and the salary between 22,000 and 200,000(randomly chosen). How would I go about doing this and how would I assign the sequence to be the primary key i.e the emp_id going from 307 to 1307?

CREATE SEQUENCE seq6
START WITH 307
INCREMENT BY 1
CACHE 10
NOCYCLE;

BEGIN
FOR i IN 1..1000 LOOP
INSERT INTO EMPLOYEE (EMP_ID, FNAME, LNAME, MANAGER_EMP_ID, salary) VALUES('307 - 1307','tommy', 'walsh', '304 or 305', 'between 22000 and 200,000');
END LOOP;
END;
/

Any ideas?

4

1 回答 1

3

使用 sequence 和 DBMS_RANDOM 包函数:

INSERT INTO EMPLOYEE (EMP_ID, FNAME, LNAME, MANAGER_EMP_ID, salary)
VALUES(seq6.nextVal,'tommy', 'walsh',
   CAST(DBMS_RANDOM.VALUE(304,305) AS INTEGER),
   CAST(DBMS_RANDOM.VALUE(22,200) AS INTEGER)*1000);
于 2013-04-24T13:59:14.973 回答