Sei sulla pagina 1di 22

OzacIe

Lab OuIde





Infosys TechnoIogies Ltd
No. 350, Hebbal Electronics City, Hootagalli
Mysore 571186


Author(s) Anubhav Pradhan
AuthorIzed by 0r. |.P. FavIndra
CreatIon 0ate |arch 2005
VersIon 1.00

0ocument Revson Hstory
EF/CDFP/CFS/0825/004 EducatIon E Fesearch 0epartment
nfosys TechnologIes LImIted Page I
0ocument PevIsIon Summary
VersIon 0ate PevIewed by Comments
0.0a 14Jul
2005
Sundar KS nItIal 0raft

1.00 24Aug
2005
Sundar KS ncorporated revIew
comments

Drccle \erson1.0

EF/CDFP/CFS/0825/004 EducatIon E Fesearch 0epartment
nfosys TechnologIes LImIted Page I
1 AssIgnments for 0ay 1 of Dracle ..................................................................... 1
1.1 Assynment 1: Solve the 00L cnd 0ML exercse ............................................ 1
2 AssIgnments for 0ay 2 of Dracle ..................................................................... J
2.1 AssIgnment 1: CreatIng fIrst PL/SQL program............................................... J
J AssIgnments for 0ay J of Dracle ..................................................................... 6
J.1 AssIgnment 1: CreatIng PL/SQL stored procedures......................................... 6
4 AssIgnments for 0ay 4 of Dracle ..................................................................... 9
4.1 AssIgnment 1: CreatIng Java stored procedures ............................................ 9
5 AssIgnments for 0ay 5 of Dracle .................................................................... 11
5.1 AssIgnment 1: UnderstandIng ExclusIve(X) Lock ........................................... 11
5.2 AssIgnment 2: Export utIlIty................................................................... 12
5.J AssIgnment J: mport utIlIty .................................................................. 1J
5.4 AssIgnment 4: SQL * Loader ................................................................... 15
5.5 Solve the followIng: ............................................................................ 17

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 1
nfosys TechnologIes LImIted
1 Assignments for Day 1 of OracIe

All the assIgnments In thIs sectIon must be completed on 0ay 1 of your Dracle course.

1.1 Assignment 1: Solve the DDL and DML exercise

DbjectIve: To practIce the 00L and 0|L statements. A refresher to your F08|S
course:

A department store has many sectIons such as Toys, CosmetIcs, ClothIng, Household
tems, and ElectronIcs etc. Each sectIon has many employees. Employees can belong
to only one sectIon. n addItIon, each sectIon also has a head that Is responsIble for
the sectIon's performance.

The department store also has many customers who purchase goods from varIous
sectIons. Customers can be of two types Fegular and Adhoc. Fegular customers get
credIt at the department store. |axImum credIt lImIt allowed Is Fs.10000.

The store procures goods from varIous supplIers. The goods are stored In a warehouse
and transferred to the store as and when requIrement comes up. QuantIty of goods
supplIed cannot be less than 0 and cannot be greater than 10000 for a partIcular
supply.

The store has a computerIzed system for all Its operatIons. CIven below are the tables
In the database:

SectIon ( SectIonNo Number(2), 0escrIptIon 7archar2(J0), SectIon_Head_EmpNo)

Employees( EmpNo Number(4), FIrst_Name 7archar2(J0), Last_Name 7archar2(J0),
Address 7archar2(J0), Crade Number(2), Salary Number(9,2), SectIonNo
Number(2), 0ate_JoIned 0ate)

Customers( CustNo Number(4), FIrst_Name 7archar2(J0), Last_Name 7archar2(J0),
CustType char(1), CredIt_LImIt Number(7,2), CredIt_Card_No Number(16),
CredIt_Card_Type 7archar2(8))

SupplIers (SuppNo Number(4), Name 7archar2(J0), Address 7archar2(J0), CIty
7archar2(J0) )

Products (ProductNo Number(4), Product_Category_Code Char(J), 0escrIptIon
7archar2(J0), PrIce Number(9,2), Qty_Dn_Hand Number(5))

Product_Category|aster(Product_Category_Code Char(J), 0escrIptIon
7archar2(15))

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 2
nfosys TechnologIes LImIted
SupplIers_Products ( SuppNo Number(4), ProductNo Number(4), 0ate_SupplIed
0ate, Qty_SupplIed Number(5))

Customers_Products( TransactIon0 Number(4), CustNo Number(4), ProductNo
Number(4), 0ate_of_Purchase 0ate, Qty_Purchased Number(5))

The column names whIch have been underlIned are the prImary keys for the tables.

Write SQL statements Ior the Iollowing using SQL *Plus. Give columns appropriate
headings and Iormats using the SQL *Plus COLUMN command.

1. Create the tables wIth all approprIate constraInts. Use the constraInts UNQUE,
NDT NULL, CHECK, PF|AFY KEY, FDFECN KEY etc. wherever necessary. Add the
tables SupplIers and SuplIers_Products to the cluster Supp_Product. Create an
Index on the cluster Supp_Product.

2. Create a sequence called Seq_Product whIch wIll start at 1 and Increment by 1.

J. Try rollIng back now. What happens:

4. Add data to the master tables and then to the other tables usIng NSEFT NTD
statements. Add at least 2 rows In each of the master tables, and 5 rows In the
other tables. WhIle InsertIng Into the product table use Seq_Product.

5. CommIt all the changes that have been made so far.

6. FInd all employees whose names begIn wIth 'A' and end wIth 'A'.

7. FInd all products whose descrIptIons have the characters 'me'.

8. FInd the total salary paId by each sectIon to employees.

9. 0Isplay the sectIon names and the names of the employees who belong to that
sectIon.

10. 0Isplay the sectIon name and the name of the person who heads the sectIon.

11. 0Isplay supplIer names and cItIes. f the cIty Is null, dIsplay 'LDCAL'. Use the N7L
functIon for thIs.

12. 0Isplay the customer names and the customer type. f the customer type Is 'F'
dIsplays 'Fegular', If the customer type Is 'A' dIsplay 'Adhoc'. Use the 0ECD0E
functIon for thIs.

1J. Try creatIng a vIew whIch when used, wIll dIsplay the supplIer names, product
names , the quantIty supplIed and the date supplIed for all records In
Supp_Products. The lIstIng should be In alphabetIcal order of supplIer names.
A vIew wIth the above specs cannot be created. Why:
How then wIll you meet the above requIrement:

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page J
nfosys TechnologIes LImIted
14. LIst all supplIers who have not supplIed any products. Use an outer joIn to do thIs.

15. 0Isplay the average salary of employees.

16. 0Isplay the customer no and the total number of products purchased by hIm, for
those customers who have purchased at least 2 or more dIfferent products. Sort
the lIstIng In ascendIng order of customer number.

17. 0Isplay the customer name and product names whIch have been purchased by hIm.
The customer and product names should be In upper case.

18. 0Isplay the products that have been supplIed more than a month ago.

19. 0Isplay employee names and the date joIned for employees. 0ate should be In the
format '00|||YYYY'.

20. 0Isplay employee names and the number of months between today's date and the
joInIng date.

21. 0Isplay product names and the prIce rounded to the nearest Integer.

22. FInd the product whIch has the greatest prIce In each category.


2 Assignments for Day 2 of OracIe
All the assIgnments In thIs sectIon must be completed on 0ay 2 of your Dracle course.

2.1 Assignment 1: Creating first PL/SQL program

DbjectIve: To understand how to wrIte, compIle and execute a PL/SQL program.

ackground: The creatIon of PL/SQL program has been explaIned to you In the
classroom. ThIs step by step guIde wIll let you understand the procedure of creatIon of
a PL/SQL program.

Note 1: 8efore runnIng thIs block type 'set serveroutput on' at the SQL Prompt In Sql*
Plus



Step 1: Create the employee relatIon In your Dracle schema:

Create table employee (
empNo number,
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 4
nfosys TechnologIes LImIted
empName varchar2(20),
empSalary number(8,2));


Step 2:

0ECLAFE
employeeNo E|P.E|PNDTYPE; employeeNo Is of the same type as E|P.E|PND
empFec E|PLDYEEFowType; empFec represents a row of Employee table

8ECN
8efore runnIng thIs block type 'set serveroutput on' at the SQL Prompt In Sql* Plus
dbms_output.enable;
employeeNo := 1;
select * Into empFec From employee where employee.EmpNo = employeeNo;
dbms_output.put_lIne('Employee 0etaIls');
dbms_output.put_lIne('________________');
dbms_output.put_lIne('Employee No.: 'to_char(employeeNo));
dbms_output.put_lIne('Employee Name: 'empFec.empName);
dbms_output.put_lIne('Salary: 'empFec.empSalary);
EN0;
/




Step 3: You'll get the followIng output:


Employee 0etaIls
________________
Employee No.: 1
Employee Name: anubhav
Salary: J0000

PL/SQL procedure successfully completed.


Summary of thIs exercIse:
You have learnt
Step by step procedure to create a PL/SQL block.
Femember thIs code Is not saved Into your database.


Note 1: Few of the questIons use the department store tables created on 0ay 1
assIgnments.


1. WrIte a PL/SQL block of code whIch wIll let you Insert a record Into the SectIon
table. Use varIables to represent the values of sectIon_no, descrIptIon and
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 5
nfosys TechnologIes LImIted
sectIon_head_empno. Use anchored declaratIons for these varIables. What
happens If you try to Insert a value of sectIon_no whIch already exIsts In the
sectIon table:

2. WrIte a PL/SQL anonymous block whIch wIll Insert 50 records Into test_table.
nsert the current date value Into the table. (Use SYS0ATE to get the system date).
[To see the value of SYS0ATE type the followIng at the SQL Prompt: SELECT
SYS0ATE FFD| 0UAL;]. (create a table called test_table, wIth 2 columns
FecordNumber (type: Number(J)) and Current0ate(type: 0ate)).


J. 0o thIs usIng the followIng:
a) 0eclare a constant |AX_FECDF0S whIch has a value of 50. Use thIs value as
the maxImum number of records to be Inserted
b) 0o thIs usIng a FDF Loop , a WhIle Loop

4. At the SQL prompt, Issue a FDLL8ACK. Try dIsplayIng the records In test_table. Can
you see all the records: f not, how can you make sure that the changes made by
the block are permanent:

5. CIven an employee number, dIsplay the followIng InformatIon to the user:
Employee name (fIrst_name + last_name)
Employee sectIon no
Employee 0esIgnatIon
DbtaIn the desIgnatIon as follows:
Crade 0esIgnatIon
1 7Ice PresIdent
2 SenIor |anager
J AssIstant |anager
4 SectIon SupervIsor
5 Sales AssIstant

Use the FDWTYPE declaratIon for obtaInIng the employee InformatIon from the
tables.

6. WrIte a PL/SQL anonymous block, whIch wIll dIsplay the product no ,
product_category code, product category descrIptIon, product descrIptIon , prIce
and quantIty on hand of all products whIch have a quantIty_on_hand of 1000 or
more. Use a cursor to obtaIn the values from the tables. Use a LDDP.EN0 LDDP to
fetch the rows from the cursor. Femember to gIve an EXT WHEN condItIon In the
loop. 0Isplay the row number of each record as It Is fetched (HInt: use
FDWCDUNT for thIs)

7. WrIte a PL/SQL anonymous block whIch wIll Increase the prIce of all products by
10, for those products whIch are In the product category 'CosmetIcs'. Use a
FDF..UP0ATE clause wIth the cursor declaratIon for thIs.

8. |odIfy problem 6 to retreIve InformatIon of employees who been In the company
for at least 2 years. AddItIonally, retreIve only the mentIoned fIelds from the
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 6
nfosys TechnologIes LImIted
table and use a FECDF0 type declaratIon In the PL./SQL code. Use a FDF loop for
fetchIng rows from the cursor. s thIs better than usIng a Loop..End Loop:

9. WrIte a PL/SQL anonymous block whIch wIll retreIve customer names and assIgn
the concatenated name(fIrst_name + last_name) to a PL/SQL table. 0Isplay the
names from the PL/SQL table.

10. For each of the above blocks of code, add the approprIate exceptIon handlers. f
you do not know of the exceptIon whIch may occur, prInt the sql error code and
error message when an unknown exceptIon occurs.


3 Assignments for Day 3 of OracIe
All the assIgnments In thIs sectIon must be completed on 0ay J of your Dracle course.

3.1 Assignment 1: Creating PL/SQL stored procedures

DbjectIve: To understand how to wrIte, compIle and execute a PL/SQL stored
procedure.

ackground: The creatIon of PL/SQL stored procedure has been explaIned to you In
the classroom. ThIs step by step guIde wIll let you understand the procedure of
creatIon of a PL/SQL stored procedure.

Note 1: 8efore runnIng thIs block type 'set serveroutput on' at the SQL Prompt In Sql*
Plus



Step 1: ConsIder the followIng employee relatIon In your Dracle schema:

Create table employee (
empNo number,
empName varchar2(20),
empSalary number(8,2),
grade char(1)
);


Step 2: WrIte the followIng code In notepad to create the stored procedure Cet_Crade
and save the fIle wIth name "getgrade.sql":

CFEATE DF FEPLACE PFDCE0UFE Cet_Crade( eNo N E|PLDYEE.EmpNoTYPE :=0 ,
eCrade DUT E|PLDYEE.CradeTYPE) S
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 7
nfosys TechnologIes LImIted
8ECN
SELECT grade Into eCrade FFD| employee WHEFE EmpNo = eNo;
EXCEPTDN
WHEN ND_0ATA_FDUN0 THEN
eCrade := 'Z';
WHEN DTHEFS THEN
eCrade :='Z';
dbms_output.put_lIne('*** Error occurred ***');
dbms_output.put_lIne('SQLCD0E: 'to_char(SQLCD0E));
dbms_output.put_lIne('SQLEFF|: 'SQLEFF|);
EN0;
/

Step 3: Execute the followIng statement at SQL prompt to compIle the stored
procedure (assumIng you have saved your procedure In E:\workarea dIrectory):

@ e:\workarea\getgrade.sqI

You wIll get the followIng output:
Procedure created.

Note 2: f there are some errors whIle compIlIng the same you can see the errors usIng
SHDW EFFDFS command at SQL PFD|PT. FectIfy error, If any and than proceed wIth
the next step.


Step 4: Stored procedure Is compIled and ready to use. Create an anonymous PL/SQL
block as gIven below to call the stored procedure Cet_Crade.

0ECLAFE
employeeNo E|PLDYEE.EmpNoTYPE;
employeeCrade E|PLDYEE.CradeTYPE;
8ECN
employeeNo := 1;
Cet_Crade(employeeNo, employeeCrade);
F employeeCrade = 'Z' THEN
dbms_output.put_lIne('Employee No Not Found');
ELSE
dbms_output.put_lIne('Employee Crade Is 'employeeCrade);
EN0 F;
EXCEPTDN
WHEN DTHEFS THEN
dbms_output.put_lIne('*** Error occurred ***');
dbms_output.put_lIne('SQLCD0E: 'to_char(SQLCD0E));
dbms_output.put_lIne('SQLEFF|: 'SQLEFF|);
EN0;
/

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 8
nfosys TechnologIes LImIted
You wIll get the followIng output (assumIng the grade of employee no 1 Is 'A'):

Employee Crade Is A

PL/SQL procedure successfully completed.


Summary of thIs exercIse:
You have learnt
Step by step procedure to create a PL/SQL stored procedure.
Femember the stored procedures are saved Into your database In a compIled
format.


Please wrIte code for the followIng requIrements:

1. Code a PL/SQL block whIch calls a procedure (not a stored procedure) to get
the total quantIty supplIed for a partIcular product. The procedure should total
the quantIty, and the callIng block should prInt the product no, product
descrIptIon and the total quantIty supplIed. The procedure should raIse an
exceptIon If the total quantIty supplIed Is 0, or the product does not exIst.

2. Convert problem above to Invoke a functIon, Instead of a procedure. The
functIon should return the total qty supplIed.

J. Code a PL/SQL block that wIll call a procedure to Insert a new record Into the
SupplIers_Products table, and also update the correspondIng Qty_Dn_Hand for
the product. The procedure should return the status of completIon to the
callIng program.

4. Code a stored procedure to Insert a new record Into the products table (InItIal
Qty_Dn_Hand should be 0). The procedure should handle approprIate
exceptIons. The productno should be obtaIned by usIng the sequence
Seq_Product. Call the stored procedure from the sql prompt or from an
anonymous block of code.

5. Create a package specIfIcatIon named E|PLDYEE_|ANACE|ENT. The package
contaIns one functIon and two procedures.
FUNCTION hireemp (name VARCHAR2, job VARCHAR2, mgr NUMBER,
hiredate DATE, sal NUMBER, comm NUMBER, deptno NUMBER) RETURN
NUMBER;
PFDCE0UFE fIre_emp (emp_Id NU|8EF);
PFDCE0UFE sal_raIse (emp_Id NU|8EF, sal_Incr NU|8EF);

6. Add a column called Location varchar2(20) to the Employees table. Run a stored
procedure, which will update the location oI each employee to the same location
as that oI the Department.

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 9
nfosys TechnologIes LImIted
7. Whenever the location oI the department changes, update the employee location
also. (Use an AFTER UPDATE trigger Ior this).

8. Add a new column called PerIormanceMeasure Number(3,1) to the EMP table.
The column can take values between 1 and 10(Use a check constraint to
implement this). Whenever the perIormance measure oI an employee is 8 or more,
insert a record into a table called EXCEPTIONALEMPLOYEES, which
contains the columns EMPNO and PERFORMANCELINKEDBONUS. Write
a |AFTER INSERT OR AFTER UPDATE| trigger Ior this.

9. Write a Statement Level Trigger that gets Iired whenever employee salaries are
updated Ior a particular grade. The trigger inserts a record into the table
SALARYUPDATELOG that contains the USERNAME, DATE OF
UPDATION oI the user who updated the salary.(Hint: To get the username oI the
user currently logged in use a data dictionary view. Consult the Oracle Server
ReIerence Manual on the Oracle Online documentation Ior the data dictionary
views.)

4 Assignments for Day 4 of OracIe
All the assIgnments In thIs sectIon must be completed on 0ay 4 of your Dracle course.


4.1 Assignment 1: Creating Java stored procedures

DbjectIve: To create a Java stored procedure whIch allows you to Insert a record In
the gIven relatIon.

ackground: The creatIon of a Java stored procedure has been explaIned to you In the
classroom. ThIs step by step guIde wIll let you understand the procedure of creatIon of
Java stored procedures.

Note 1: t Is assumed that the user Is scott and hIs password Is tIger. The host strIng of
Dracle Is traInIng. You have to logIn usIng your username and password. Please do the
necessary changes wIth respect to thIs In the forthcomIng steps.


Step 1: Create the employee relatIon In your Dracle schema:

Create table employee (
emp_Id number,
emp_f_name varchar2(20),
emp_l_name varchar2(20),
emp_salary number(8,2),
dept_Id number);

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 10
nfosys TechnologIes LImIted
Step 2: Add followIng classes In your CLASSPATH varIable:

c:\j2sdk1.4.2_0J\jre;.;E:\oracle\ora90\jdbc\lIb\classes12.zIp;E:\oracle\ora90\sqlj\lIb\tr
anslator.zIp;E:\oracle\ora90\sqlj\lIb\runtIme.zIp

Step 3: Use any 0E or notepad to create the Emp|anager class. Here Is the defInItIon
of the class:

Import java.sql.*;
Import oracle.jdbc.*;

publIc class Emp|anager [
//Add an employee to the database.
publIc statIc voId addEmp(Int emp_Id, StrIng emp_f_name, StrIng emp_l_name, float
emp_salary, Int dept_Id) [
System.out.prIntln(CreatIng new employee...);
try [
ConnectIon conn = 0rIver|anager.getConnectIon(jdbc:default:connectIon:);
StrIng sql=NSEFT NTD employee +
(emp_Id,emp_f_name,emp_l_name,emp_salary,dept_Id) +
7ALUES(:,:,:,:,:);
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setnt(1,emp_Id);
pstmt.setStrIng(2,emp_f_name);
pstmt.setStrIng(J,emp_l_name);
pstmt.setFloat(4,emp_salary);
pstmt.setnt(5,dept_Id);
pstmt.executeUpdate();
pstmt.close();
]
catch(SQLExceptIon e) [
System.err.prIntln(EFFDF! AddIng Employee: + e.get|essage());
]
]
]

Save the fIle and compIle It.

Step 4: Load the Java class usIng loadjava utIlIty.
Dpen command prompt and Issue the followIng command:

loadjava u scott/tIger@traInIng v r Emp|anager.class


Step 5: Create the followIng PL/SQL wrapper for Java method In your Dracle schema:

CFEATE DF FEPLACE PFDCE0UFE add_emp
(emp_Id NU|8EF,
emp_f_name 7AFCHAF2,
emp_l_name 7AFCHAF2,
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 11
nfosys TechnologIes LImIted
emp_salary NU|8EF,
dept_Id NU|8EF)
AS LANCUACE JA7A
NA|E 'Emp|anager.addEmp(Int, java.lang.StrIng, java.lang.StrIng,float, Int)';

Save and compIle It.

Step 6: FInally we have to call the java stored procedure.

ssue the followIng command In your Dracle schema:

SET SEF7EFDUTPUT DN
CALL dbms_java.set_output(2000);

EXECUTE add_emp(1,'Anubhav', 'Pradhan',50000.00,1);


Step 7: Ensure the InsertIon by executIng the followIng command at SQL prompt:

SELECT * FFD| employee;

Summary of thIs exercIse:
You have learnt
Step by step procedure to create a Java stored procedure.
n the next assIgnment, we shall extend the functIonalIty of our Java stored
procedure.


2. Add followIng functIonalIty In add_emp Java stored procedure:

a) Create a Java method in EmpManager that fetch all the details from the
employee table.

b) Create a Java method in EmpManager that obtains a count of employees for a
given department



5 Assignments for Day 5 of OracIe
All the assIgnments In thIs sectIon must be completed on 0ay 5 of your Dracle course.

5.1 Assignment 1: Understanding ExcIusive(X) Lock
DbjectIve: To learn about the exclusIve lock.

ackground: The dIfferent lockIng mechanIsms have been explaIned to you In the
classroom. For practIce we wIll use E|PLDYEES table (whIch you have used In
AssIgnments for 0ay1).
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 12
nfosys TechnologIes LImIted

Note: n Dracle the default lockIng Is row exclusIve lock for Update/0elete/nsert.

Step 1: Dpen two Instances of SQLPLUS on your machIne and logIn wIth your Dracle 0
In both the Instances.

Step 2: Co to fIrst Instance.
WrIte the followIng query:

update employees set salary=9000 where empno=7J69;

Step 3: Co to the second Instance.
WrIte the followIng query:

update employees set salary=6000 where empno=7J69;

Note: The second Instance Is hanged. The reason Is the fIrst transactIon has Issued the
update statement for the empno 7J69 and It acquIres the exclusIve(X) lock. The
second transactIon Is also tryIng to update the same but because of the X lock
acquIred by the fIrst transactIon It has to waIt.

Step 4: Co to the fIrst Instance and Issue CD||T/FDLL8ACK.

Step 5: Co to the second Instance. You get the SQL prompt.
Note: As soon as you CommIt/Follback the transactIon In second Instance the X lock Is
released.

Step 6: ssue CD||T/FDLL8ACK In the second Instance as well.


Summary of thIs exercIse:
You have just learnt
Update/0elete/nsert 0|L statement acquIre a row exclusIve lock
The X lock Is released only at the end of transactIon whIch Is marked by
CommIt/Follback.

5.2 Assignment 2: Export utiIity

DbjectIve: To learn the usage of Export utIlIty and understand the procedure of
performIng logIcal backup or data transfer. Here we are exportIng emp and dept table
from the scott schema.

ackground: The usage of mport utIlIty has been explaIned to you In the classroom.
ThIs step by step guIde wIll let you understand to Implement the same.

Note 1: t Is assumed that the user Is scott and hIs password Is tIger. The host strIng of
Dracle Is traInIng. You have to logIn usIng your username and password. Please do the
necessary changes wIth respect to thIs In the forthcomIng steps.
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 1J
nfosys TechnologIes LImIted


Step 1: Dpen command prompt (Type cmd In Fun)
Type the followIng at command prompt:

exp scottltIger fIIe=empdept.expdat tabIes=(EhP,0EPT) Iog=empdept.Iog


Step 2: You wIll see the followIng output:

Export: Felease 9.0.1.1.1 ProductIon on Wed |ar J0 09:J2:2J 2005

(c) CopyrIght 2001 Dracle CorporatIon. All rIghts reserved.

Connected to: Dracle9I EnterprIse EdItIon Felease 9.0.1.1.1 ProductIon
WIth the PartItIonIng optIon
JServer Felease 9.0.1.1.1 ProductIon
Export done In WE8|SWN1252 character set and AL16UTF16 NCHAF character set

About to export specIfIed tables vIa ConventIonal Path ...
. . exportIng table E|P 14 rows exported
. . exportIng table 0EPT 4 rows exported
Export termInated successfuIIy wIthout warnIngs.


Step 3: ThIs command wIll create two fIles:
empdept.expdat: export dump fIle contaInIng the data from the table emp and dept.
empdept.log: export log fIle contaInIng the log InformatIon about the export
operatIon.

Step 4: f you are unable to see the message statIng, "Export termInated successfuIIy
wIthout warnIngs", open the log fIle empdept.log and follow the dIrectIons as
mentIoned In the log fIle for successfully exportIng your data.

Summary of thIs exercIse:
You have learnt
Step by step procedure to export your data.
n the next assIgnment, we wIll learn how to Import your data.


5.3 Assignment 3: Import utiIity

DbjectIve: To learn the usage of mport utIlIty and understand the procedure of
restorIng your data from the export dump fIle. Here we are ImportIng the data from
empdept.expdat export dump fIle whIch Is holdIng the data from emp and dept table
of scott schema.

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 14
nfosys TechnologIes LImIted
ackground: The usage of mport utIlIty has been explaIned to you In the classroom.
ThIs step by step guIde wIll let you understand to Implement the same.

Note 1: PIease do thIs exercIse In a group of two.
t Is assumed that the user Is user1 and hIs password Is user1. The host strIng of Dracle
Is traInIng. You have to logIn usIng your partner's username and password. Please do
the necessary changes wIth respect to thIs In the forthcomIng steps.


Step 1: Dpen command prompt (Type cmd In Fun)
Type the followIng at command prompt:

Imp user1luser1 tabIes=( EhP,0EPT)


Step 2: You wIll see the followIng output:

mport: Felease 9.0.1.1.1 ProductIon on Wed |ar J0 09:4J:41 2005

(c) CopyrIght 2001 Dracle CorporatIon. All rIghts reserved.


Connected to: Dracle9I EnterprIse EdItIon Felease 9.0.1.1.1 ProductIon
WIth the PartItIonIng optIon
JServer Felease 9.0.1.1.1 ProductIon

|P00002: faIled to open EXP0AT.0|P for read
mport fIle: EXP0AT.0|P

At thIs prompt type the name of the export fIIe whIch you have created In the
assIgnment no.1.

Type: empdept.expdat

Note 2: Take care of the path where you have saved thIs fIle. 8y default thIs Is saved
In the c:\0ocuments and SettIngs\user_name folder.

Step 3: You wIll see the followIng output:

Export fIle created by EXPDFT:709.00.01 vIa conventIonal path

WarnIng: the objects were exported by SCDTT, not by you

Import done In WE8|SWN1252 character set and AL16UTF16 NCHAF character set
. ImportIng SCDTT's objects Into SYSTE|
. . ImportIng table E|P 14 rows Imported
. . ImportIng table 0EPT 4 rows Imported
About to enable constraInts...
mport termInated successfully wIthout warnIngs.

Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 15
nfosys TechnologIes LImIted

Step 4: You can verIfy the data by loggIng In the user1 schema and IssuIng the
followIng command:

Select * from emp;
Select * from dept;

Summary of thIs exercIse:
You have learnt
Step by step procedure to Import your data.
n the next assIgnment, we wIll learn how to use SQL * Loader.


5.4 Assignment 4: SQL * Loader

DbjectIve: To learn the usage of SQL * Loader and understand the procedure of
transportIng data. Here we are loadIng a UnIx module mark sheet (XLS) of a FP batch
taken from perceptIon server (examInatIon server) Into Dracle.


ackground: The usage of SQL * Loader has been explaIned to you In the classroom.
ThIs step by step guIde wIll let you understand to Implement the same.

Note 1: t Is assumed that the user Is scott and hIs password Is tIger. The host strIng of
Dracle Is traInIng. You have to logIn usIng your username and password. Please do the
necessary changes wIth respect to thIs In the forthcomIng steps.


Step 1: Create an excel sheet as shown you In the theory sessIon (SlIde#18).


Step 2: Save the excel sheet as .CS7 fIle. Co to save as. In fIIe menu and chose .csv
from the lIst box statIng save as type.

Note 2: Now your data Is ready whIch you can load Into Dracle. ThIs data may come
from any source I.e. from SQL Server 2000, 082, U08, etc.


Step 3: UsIng notepad, create a fIle (say, e:\workarea\marksheet.ctl) contaInIng these
lInes:

LDA0 0ATA
NFLE 'E:\workarea\marksheet.csv'
FEPLACE
NTD TA8LE scott.marks
FEL0S TEF|NATE0 8Y ',' DPTDNALLY ENCLDSE0 8Y ''
TFALNC NULLCDLS
(empId NTECEF EXTEFNAL,
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 16
nfosys TechnologIes LImIted
quIz1 NTECEF EXTEFNAL,
quIz2 NTECEF EXTEFNAL,
test NTECEF EXTEFNAL,
total NTECEF EXTEFNAL,
grade
)

Save the fIIe.

Note J: 8efore runnIng SQL * Loader you have to create the followIng table In your
schema (here scott) whIch acts as destInatIon to receIve the data comIng from the csv
fIle.


Step 4: Dpen the SQL * Plus and execute the followIng 00L:

create table marks(
empId number,
quIz1 number,
quIz2 number,
test number,
total number,
grade char(1));


Step 5: At |S0DS prompt (or the Start, Fun menu), execute SQL*Loader as follows:

sqIIdr scottltIger@traInIng controI=e:\workarea\marksheet.ctI


Step 6: You wIll see the followIng output:

SQL*Loader: Felease 9.0.1.1.1 ProductIon on Wed |ar J0 10:07:11 2005

(c) CopyrIght 2001 Dracle CorporatIon. All rIghts reserved.

CommIt poInt reached logIcal record count 64
CommIt poInt reached logIcal record count 89

Step 7: You can see your loaded data wIth your favorIte:

SeIect * from marks;

Check the log fIle as well.

Note J: 8y default the log fIle Is present In c:\documents and
settIngs\user_name\marksheet.


Summary of thIs exercIse:
Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 17
nfosys TechnologIes LImIted
You have learnt
Step by step procedure to use SQL * Loader.
n the next assIgnments, you have to solve the exercIses on these utIlItIes.

5.5 SoIve the foIIowing:

1. Export the customers table whIch you have created on 0ay1.

2. mport the supplIers table of your partner whIch you have created on 0ay2.

J. Create an excel sheet comprIsIng of followIng data:
Employee number, Employee name and Employee bIrthday
Enter few records.
Use SQL * Loader to load thIs data Into your Dracle schema.


































Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 18
nfosys TechnologIes LImIted


Drccle \erson1.0

EducatIon E Fesearch 0epartment Page 19
nfosys TechnologIes LImIted

Potrebbero piacerti anche