2010
ORACLE Fundamental_ SQL 1 أ أوراآ
Mustafa
إهاء إWWW.ARAB
/OUG/HARDWARE/TEAM2000
3/21/2010
LES 08 Manipulating Data
Practice 8
The HR department wants you to create SQL statements to insert, update, and delete employee data.
As a prototype, you use the MY_EMPLOYEE table, prior to giving the statements to the HR
department.
Insert data into the MY_EMPLOYEE table.
1. Run the statement in the lab_08_01.sql script to build the MY_EMPLOYEE table to be used for the lab.
2. Describe the structure of the MY_EMPLOYEE table to identify the column names.
. ء اول و" ! ض اء اا ول ا#! "وز% :2& 1*ال+ ا
DESC my_employee
3.Create an INSERT statement to 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. Do not enter all rows yet.
ID LAST_NAME FIRST_NAME USERID SALARY
ول ا- ول. ا/0ت ا23 ! " وز% :3 *ال+ ا
1 Patel Ralph rpatel 895
. - 7%. اول دون ذآ أء ا-4 زى/6 ت اول23و
2 Dancs Betty bdancs 860
Insert into my_ employee
3 Biri Ben bbiri 1100
4 Newman Chad cnewman 750
Values
5 Ropeburn Audrey aropebur 1550
(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.
5. Confirm your addi3on to the table.
Insert into my_ employee ; ذآ أء4 3 ـ- = ا ا2 وز% : 5&4 *ال+ ا
(ID,Last_name,First_name,Userid,Salary)
Values .3،4 @ اAB@ "و، 7%.ا
(1,’Patel’,’Ralph’,’rpatel’,895);
-------------------------
Commit ;
6.Write an insert statement in a dynamic reusable script 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 user ID. Save this script to a file named lab_08_06.sql.
وف7 ول واول. اF. ا4 ول.ف اG اH4; د4 "ول ا- /6 I4J " إدل دL@ اآ:8&7&6 *ال+ ا
. ا3! وWGن اBJ 4@; وا3+ || واH4; ودا اBT\دام اا اP@Q3 R ازر وذFO ر. اF. ا4
insert into my_employee
(id ,last_name,first_name,userid ,salary )
values
(&ID,'&&first_name','&&last_name',substr('&first_name',0,1)||substr('&last_name',0,7),&salary)
.ف0 اR! ب إدلBا
COMMIT;
9.Make the data addi3ons permanent.
Update and delete data in the MY_EMPLOYEE table.
10.Change the last name of employee 3 to Drexler.
11.Change the salary to $1,000 for all employees who have a salary less than $900.
12.Verify your changes to the table.
1- SQL> update .3 FO ر/ . اF. اY@3 ول- J @ اLBJ : [ً أو:12-9 *ال+ ا
my_employee
.1000 إ900 4 O أF هL! اY! : ً 2^
set last_name='Drelex'
. dT- آc! e"ر.= ا3 هf2 I4 اول و- تbJ @ ا4 آc! : ً a^
where id=3;
1row updated.
2- update my_employee
set salary=1000
where salary <900;
3- select *
From employee;
COMMIT;
13.Delete Betty Dancs from the MY_EMPLOYEE table.
14.Confirm your changes to the table.
15. Commit all pending changes.
. f2ت وbJ @ ا4 آc! F^، اول4.. /ف اfG3 FO: 15&14 &13 *ال+ ا
delete from my_employee
where last_name='Betty';--
Commit;
Control data transaction to the MY_EMPLOYEE table.
16. Populate the table with the last row of sample data by using the statements in the script
that you created in step 6. Run the statements in the script.
17.Confirm your addition to the table.
ام اg@Q3 . ا/0 ا-hوز إ% :17&16 *ال+ ا
Select *… 3 آc@وز ا% وآن،ً i j...6 *ال+ا
18. Mark an intermediate point in the processing of the transaction.
19. Empty the entire table.
20. Confirm that the table is empty.
21. Discard the most recent DELETE operation without discarding the earlier INSERT operation.
22. Confirm that the new row is still intact.
23. Make the data addition permanent.
: بB ا:23-18 *ال+ ا
. Savepoint W BT2 % :[ً أو
. ت2 ا4 r!J@G4 4 غ اول- : ً 2^
. ت دا اول23 م و"د% 4 آc! : ً a^
. فfG اtT @ اWG اBT "ع3 R وذj@T @ ا-hv ا% ءYة دون إ.ف اfG ا% ءY إ: ً 3را
. ض اول3 Rف وذfG ا% ;" ا@ا% 3 J ا/0 و"د ا4 !آ: ً +4
. r@3^ وx\ داFت ا2 إ" ا: ً د
1-SQL> savepoint sv_emp_1;
Savepoint created.
2-SQL> delete my_employee
4 rows deleted.
3-SQL> select *
from my_employee;
no rows selected.
4-SQL> rollback to sv_emp_1;
Rollback complete.
5-SQL> select *
from my_employee
where id=5;
6- SQL> commit ;
Commit complete.