|
| 1 | +-- Employees Table |
| 2 | +CREATE TABLE employees ( |
| 3 | + id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 4 | + name VARCHAR2(255) NOT NULL, |
| 5 | + email VARCHAR2(255) NOT NULL, |
| 6 | + department VARCHAR2(255) NOT NULL |
| 7 | +); |
| 8 | + |
| 9 | +-- Insert 50 records in 'employees' table |
| 10 | +INSERT INTO employees (name, email, department) VALUES ('John Doe', 'john.doe@example.com', 'Sales'); |
| 11 | +INSERT INTO employees (name, email, department) VALUES ('Jane Smith', 'jane.smith@example.com', 'Marketing'); |
| 12 | +INSERT INTO employees (name, email, department) VALUES ('Bob Johnson', 'bob.johnson@example.com', 'Finance'); |
| 13 | +INSERT INTO employees (name, email, department) VALUES ('Mary Brown', 'mary.brown@example.com', 'Human Resources'); |
| 14 | +INSERT INTO employees (name, email, department) VALUES ('David Lee', 'david.lee@example.com', 'Engineering'); |
| 15 | +INSERT INTO employees (name, email, department) VALUES ('Sarah Green', 'sarah.green@example.com', 'Sales'); |
| 16 | +INSERT INTO employees (name, email, department) VALUES ('Mike Davis', 'mike.davis@example.com', 'Marketing'); |
| 17 | +INSERT INTO employees (name, email, department) VALUES ('Karen Wilson', 'karen.wilson@example.com', 'Finance'); |
| 18 | +INSERT INTO employees (name, email, department) VALUES ('Tom Johnson', 'tom.johnson@example.com', 'Human Resources'); |
| 19 | +INSERT INTO employees (name, email, department) VALUES ('Lisa Chen', 'lisa.chen@example.com', 'Engineering'); |
| 20 | +INSERT INTO employees (name, email, department) VALUES ('David Davis', 'david.davis@example.com', 'Sales'); |
| 21 | +INSERT INTO employees (name, email, department) VALUES ('Michelle Rodriguez', 'michelle.rodriguez@example.com', 'Marketing'); |
| 22 | +INSERT INTO employees (name, email, department) VALUES ('Christopher Smith', 'christopher.smith@example.com', 'Finance'); |
| 23 | +INSERT INTO employees (name, email, department) VALUES ('Samantha Brown', 'samantha.brown@example.com', 'Human Resources'); |
| 24 | +INSERT INTO employees (name, email, department) VALUES ('Charles Kim', 'charles.kim@example.com', 'Engineering'); |
| 25 | +INSERT INTO employees (name, email, department) VALUES ('Alexandra Taylor', 'alexandra.taylor@example.com', 'Sales'); |
| 26 | +INSERT INTO employees (name, email, department) VALUES ('Richard Wilson', 'richard.wilson@example.com', 'Marketing'); |
| 27 | +INSERT INTO employees (name, email, department) VALUES ('Jennifer Lee', 'jennifer.lee@example.com', 'Finance'); |
| 28 | +INSERT INTO employees (name, email, department) VALUES ('Matthew Jones', 'matthew.jones@example.com', 'Human Resources'); |
| 29 | +INSERT INTO employees (name, email, department) VALUES ('Ava Chen', 'ava.chen@example.com', 'Engineering'); |
| 30 | +INSERT INTO employees (name, email, department) VALUES ('William Davis', 'william.davis@example.com', 'Sales'); |
| 31 | +INSERT INTO employees (name, email, department) VALUES ('Natalie Nguyen', 'natalie.nguyen@example.com', 'Marketing'); |
| 32 | +INSERT INTO employees (name, email, department) VALUES ('Joseph Garcia', 'joseph.garcia@example.com', 'Finance'); |
| 33 | +INSERT INTO employees (name, email, department) VALUES ('Rachel Martin', 'rachel.martin@example.com', 'Human Resources'); |
| 34 | +INSERT INTO employees (name, email, department) VALUES ('Christian Kim', 'christian.kim@example.com', 'Engineering'); |
| 35 | +INSERT INTO employees (name, email, department) VALUES ('Hannah Rodriguez', 'hannah.rodriguez@example.com', 'Sales'); |
| 36 | +INSERT INTO employees (name, email, department) VALUES ('Anthony Johnson', 'anthony.johnson@example.com', 'Marketing'); |
| 37 | +INSERT INTO employees (name, email, department) VALUES ('Sophia Wilson', 'sophia.wilson@example.com', 'Finance'); |
| 38 | +INSERT INTO employees (name, email, department) VALUES ('Ethan Chen', 'ethan.chen@example.com', 'Human Resources'); |
| 39 | +INSERT INTO employees (name, email, department) VALUES ('Madison Smith', 'madison.smith@example.com', 'Engineering'); |
| 40 | +INSERT INTO employees (name, email, department) VALUES ('Oliver Davis', 'oliver.davis@example.com', 'Sales'); |
| 41 | +INSERT INTO employees (name, email, department) VALUES ('Grace Nguyen', 'grace.nguyen@example.com', 'Marketing'); |
| 42 | +INSERT INTO employees (name, email, department) VALUES ('Daniel Garcia', 'daniel.garcia@example.com', 'Finance'); |
| 43 | +INSERT INTO employees (name, email, department) VALUES ('Isabella Martin', 'isabella.martin@example.com', 'Human Resources'); |
| 44 | +INSERT INTO employees (name, email, department) VALUES ('Mia Kim', 'mia.kim@example.com', 'Engineering'); |
| 45 | +INSERT INTO employees (name, email, department) VALUES ('Lucas Rodriguez', 'lucas.rodriguez@example.com', 'Sales'); |
| 46 | +INSERT INTO employees (name, email, department) VALUES ('Victoria Johnson', 'victoria.johnson@example.com', 'Marketing'); |
| 47 | +INSERT INTO employees (name, email, department) VALUES ('David Wilson', 'david.wilson@example.com','Engineering'); |
| 48 | +INSERT INTO employees (name, email, department) VALUES ('Steven Nguyen', 'steven.nguyen@example.com', 'Marketing'); |
| 49 | +INSERT INTO employees (name, email, department) VALUES ('Amy Kim', 'amy.kim@example.com', 'Engineering'); |
| 50 | +INSERT INTO employees (name, email, department) VALUES ('Anna Martinez', 'anna.martinez@example.com', 'Sales'); |
| 51 | +INSERT INTO employees (name, email, department) VALUES ('Kevin Kim', 'kevin.kim@example.com', 'Marketing'); |
| 52 | +INSERT INTO employees (name, email, department) VALUES ('Catherine Davis', 'catherine.davis@example.com', 'Finance'); |
| 53 | +INSERT INTO employees (name, email, department) VALUES ('Robert Nguyen', 'robert.nguyen@example.com', 'Human Resources'); |
| 54 | +INSERT INTO employees (name, email, department) VALUES ('Karen Clark', 'karen.clark@example.com', 'Engineering'); |
| 55 | +INSERT INTO employees (name, email, department) VALUES ('Mike Wilson', 'mike.wilson@example.com', 'Sales'); |
| 56 | +INSERT INTO employees (name, email, department) VALUES ('Rachel Lee', 'rachel.lee@example.com', 'Marketing'); |
| 57 | +INSERT INTO employees (name, email, department) VALUES ('Thomas Johnson', 'thomas.johnson@example.com', 'Finance'); |
| 58 | +INSERT INTO employees (name, email, department) VALUES ('Emily White', 'emily.white@example.com', 'Human Resources'); |
| 59 | +INSERT INTO employees (name, email, department) VALUES ('Brian Brown', 'brian.brown@example.com', 'Engineering'); |
| 60 | +commit; |
| 61 | + |
| 62 | +-- Procedure to Generate Sample Data |
| 63 | +CREATE OR REPLACE PROCEDURE add_employees ( |
| 64 | + n IN NUMBER |
| 65 | +) |
| 66 | +AS |
| 67 | + departments employees.department%TYPE := 'Sales,Marketing,Finance,Human Resources,Engineering'; |
| 68 | +BEGIN |
| 69 | + FOR i IN 1..n LOOP |
| 70 | + INSERT INTO employees (name, email, department) |
| 71 | + VALUES ('Employee ' || i, 'employee' || i || '@example.com', REGEXP_SUBSTR(departments,'[^,]+',1,ROUND(DBMS_RANDOM.VALUE(1,5)))); |
| 72 | + END LOOP; |
| 73 | + COMMIT; |
| 74 | +END; |
| 75 | +/ |
| 76 | + |
| 77 | +-- Generate Sample Employee Data |
| 78 | +BEGIN |
| 79 | + add_employees(50); |
| 80 | +END; |
| 81 | +/ |
| 82 | + |
| 83 | +-- Employees Salary Table |
| 84 | +CREATE TABLE employees_salary ( |
| 85 | + id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, |
| 86 | + employee_id NUMBER NOT NULL, |
| 87 | + salary NUMERIC(10, 2) NOT NULL, |
| 88 | + start_date DATE NOT NULL, |
| 89 | + end_date DATE NOT NULL, |
| 90 | + bonus FLOAT NOT NULL |
| 91 | + ); |
| 92 | + |
| 93 | +-- Procedure to Generate Sample Data |
| 94 | +CREATE OR REPLACE PROCEDURE generate_employees_salary(n IN NUMBER) AS |
| 95 | +BEGIN |
| 96 | + FOR i IN 1..n LOOP |
| 97 | + INSERT INTO employees_salary (employee_id, salary, start_date, end_date, bonus) |
| 98 | + VALUES (FLOOR(DBMS_RANDOM.VALUE(1, 10)), -- generate random employee_id between 1 and 10 |
| 99 | + ROUND(DBMS_RANDOM.VALUE(50000, 100000), 2), -- generate random salary between 50000 and 100000 with 2 decimal places |
| 100 | + TRUNC(SYSDATE - DBMS_RANDOM.VALUE(1, 365)), -- generate random start_date between 1 and 365 days ago |
| 101 | + TRUNC(SYSDATE + DBMS_RANDOM.VALUE(1, 365)), -- generate random end_date between today and 365 days from now |
| 102 | + ROUND(DBMS_RANDOM.VALUE(5000, 15000), 2)); -- generate random bonus between 5000 and 15000 with 2 decimal places |
| 103 | + END LOOP; |
| 104 | + COMMIT; |
| 105 | +END; |
| 106 | +/ |
| 107 | + |
| 108 | +-- Generate Sample Employee Salary Data |
| 109 | +BEGIN |
| 110 | + generate_employees_salary(50); -- generate 50 random records |
| 111 | +END; |
| 112 | +/ |
| 113 | + |
| 114 | +-- Cleanup |
| 115 | +-- drop table employees; |
| 116 | +-- drop table employees_salary; |
| 117 | +-- drop procedure generate_employees_salary; |
| 118 | +-- drop procedure add_employees; |
0 commit comments