Insert data into the MY_EMPLOYEE table.
1. Run the statement in the lab8_1.sql script to build the MY_EMPLOYEE table that
will be used
for the lab.
CREATE TABLE my_employee
(id NUMBER(4) CONSTRAINT my_employee_id_nn NOT NULL,
last_name VARCHAR2(25),
first_name VARCHAR2(25),
userid VARCHAR2(8),
salary NUMBER(9,2));
2. Describe the structure of the MY_EMPLOYEE table to identify the column names.
DESCRIBE my_employee
3. Add the first row of data to the MY_EMPLOYEE table from the following sample
data. Do not list
the columns in the INSERT clause.
ID LAST_NAME FIRST_NAME USERID SALARY
1 Patel Ralph rpatel 895
2 Dancs Betty bdancs 860
3 Biri Ben bbiri 1100
4 Newman Chad cnewman 750
5 Ropeburn Audrey aropebur 1550
INSERT INTO my_employee
VALUES (1, �Patel�, �Ralph�, �rpatel�, 895);
4. Populate the MY_EMPLOYEE table with the second row of sample data from the
preceding list.
This time, list the columns explicitly in the INSERT clause.
INSERT INTO my_employee (id, last_name, first_name,
userid, salary)
VALUES (2, �Dancs�, �Betty�, �bdancs�, 860);
5. Confirm your addition to the table.
SELECT *
FROM my_employee;
ID LAST_NAME FIRST_NAME USERID SALARY
1 Patel Ralph rpatel 895
2 Dancs Betty bdancs 860
3 Biri Ben bbiri 1100
4 Newman Chad cnewman 750
5 Ropeburn Audrey aropebur 1550
6. Write an insert statement in a text file named loademp.sql to load rows into the
MY_EMPLOYEE table. Concatenate the first letter of the first name and the first
seven characters
of the last name to produce the userid.
SET ECHO OFF
SET VERIFY OFF
INSERT INTO my_employee
VALUES (&p_id, �&p_last_name�, �&p_first_name�,
lower(substr(�&p_first_name�, 1, 1) ||
substr(�&p_last_name�, 1, 7)), &p_salary);
SET VERIFY ON
SET ECHO ON
7. Populate the table with the next two rows of sample data by running the insert
statement in the
script that you created.
SET ECHO OFF
SET VERIFY OFF
INSERT INTO my_employee
VALUES (&p_id, �&p_last_name�, �&p_first_name�,
lower(substr(�&p_first_name�, 1, 1) ||
substr(�&p_last_name�, 1, 7)), &p_salary);
SET VERIFY ON
SET ECHO ON
8. Confirm your additions to the table.
SELECT *
FROM my_employee;
9. Make the data additions permanent.
COMMIT;
Update and delete data in the MY_EMPLOYEE table.
10. Change the last name of employee 3 to Drexler.
UPDATE my_employee
SET last_name = �Drexler�
WHERE id = 3;
11. Change the salary to 1000 for all employees with a salary less than 900.
UPDATE my_employee
SET salary = 1000
WHERE salary < 900;
12. Verify your changes to the table.
SELECT last_name, salary
FROM my_employee;
13. Delete Betty Dancs from the MY_EMPLOYEE table.
DELETE
FROM my_employee
WHERE last_name = �Dancs�;
14. Confirm your changes to the table.
SELECT *
FROM my_employee;
15. Commit all pending changes.
COMMIT;
Control data transaction to the MY_EMPLOYEE table.
16. Populate the table with the last row of sample data by modifying the statements
in the script that
you created in step 6. Run the statements in the script.
SET ECHO OFF
SET VERIFY OFF
INSERT INTO my_employee
VALUES (&p_id, �&p_last_name�, �&p_first_name�,
lower(substr(�&p_first_name�, 1, 1) ||
substr(�&p_last_name�, 1, 7)), &p_salary);
SET VERIFY ON
SET ECHO ON
17. Confirm your addition to the table.
SELECT *
FROM my_employee;
18. Mark an intermediate point in the processing of the transaction.
SAVEPOINT step_18;
19. Empty the entire table.
DELETE
FROM my_employee;
20. Confirm that the table is empty.
SELECT *
FROM my_employee;
21. Discard the most recent DELETE operation without discarding the earlier INSERT
operation.
ROLLBACK TO step_18;
22. Confirm that the new row is still intact.
SELECT *
FROM my_employee;
23. Make the data addition permanent.
COMMIT;