Vous êtes sur la page 1sur 7

Assignment-5

Question 1: Insert this data to DEPARTMENT table using SQL*LOADER


120,RESEARCH,"SARATOGA" 10,"ACCOUNTING",CLOVELAND 11,"ART",SALEM AA,FINANCE,"BOSTON" 21,"SALES",ROCHESTER 42,"INT'L","SAN FRANCISCO" Ans: Ctl file is LOAD DATA INFILE 'C:\Users\jagmeet\Desktop\Department.txt' INTO TABLE Dept FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (deptno,dname,loc) First row will not be inserted as its deptno length is more than 2

Question 2: Basic import of fixed length data with separate data and control files. Insert into
EMP table:
7782 7839 7934 7566 7499 7654 7658 7654 CLARK KING MILLER JONES ALLEN MARTIN CHAN MARTIN MANAGER PRESIDENT CLERK MANAGER SALESMAN SALESMAN ANALYST SALESMAN 7839 7782 7839 7698 7698 7566 7698 2572.50 5500.00 920.00 3123.75 1600.00 1312.50 3450.00 1312.50 10 10 10 20 300.00 30 1400.00 30 20 1400.00 30

ANS: LOAD DATA INFILE 'C:\Users\jagmeet\Desktop\emp.txt' INTO TABLE emp FIELDS TERMINATED BY ' ' OPTIONALLY ENCLOSED BY '"' (empno position(01:04) integer external, ename position(06:15) char, job position(17:25) char, mgr position(27:30) integer external , sal position(33:39) decimal external , comm position(42:48) decimal external,

deptno )

position(50:51) integer external

We have to specify external with integer as basic data types understand by sqlloader is varchar,char,lob. External integer will tell us that data will com in integer form from outside

Question 3: Append into EMP using delimited data with data in the control file. This
demonstrates date formating, delimiters within delimiters and implementation of record numbering with a SQL*Loader sequence. APPEND indicates that the table need not be empty before the SQL*Loader is run.
7782, 7839, 7934, 7566, 7499, (same 7654, (same 7658, "Clark", "Manager", 7839, 09-June-1981, 2572.50,, 10:101 "King", "President", , 17-November-1981,5500.00,,10:102 "Miller", "Clerk", 7782, 23-January-1982, 920.00,, 10:102 "Jones", "Manager", 7839, 02-April-1981, 3123.75,, 20:101 "Allen", "Salesman", 7698, 20-February-1981, 1600.00, line continued) 300.00, 30:103 "Martin", "Salesman", 7698, 28-September-1981, 1312.50, line continued) 1400.00, 3:103 "Chan", "Analyst", 7566, 03-May-1982, 3450,, 20:101

(REFER TABLE) Ans: final field of table is loadseq. We hav to generate it automatically using sqlloader sequence using loadseq sequence(max,1), Also for date: hiredate date dd-mm-yyyy, Deptno terminated by :, LOAD DATA INFILE * APPEND INTO TABLE emp FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (empno , ename , job , mgr , hiredate date "dd-month-yyyy", sal , comm , deptno terminated by ":", projno, loadseq sequence(max,1) ) begindata 7782, "Clark", "Manager", 7839, 09-June-1981, 2572.50,, 10:101 7839, "King", "President", , 17-November-1981,5500.00,,10:102 7934, "Miller", "Clerk", 7782, 23-January-1982, 920.00,, 10:102 7566, "Jones", "Manager", 7839, 02-April-1981, 3123.75,, 20:101 7499, "Allen", "Salesman", 7698, 20-February-1981, 1600.00, 300.00, 30:103 7654, "Martin", "Salesman", 7698, 28-September-1981, 1312.50,

1400.00, 3:103 7658, "Chan", "Analyst", 7566, 03-May-1982, 3450,,

20:101

Question 4: Replace of fixed length data with separate data and control file. This sample
demonstrates specifying a discard file, the maximum number of records to discard (DISCARDMAX), and CONTINUEIF ( where it looks for an asterisk in the first position to determine if a new line has started.
*7782 CLARK MANAGER 7839 *7839 KING PRESIDENT *7934 MILLER CLERK 7782 *7566 JONES MANAGER 7839 *7499 ALLEN SALESMAN 7698 *7654 MARTIN SALESMAN 7698 *7658 CHAN ANALYST 7566 * CHEN ANALYST 7566 *7658 CHIN ANALYST 7566 2572.50 5500.00 920.00 3123.75 1600.00 1312.50 3450.00 3450.00 3450.00 300.00 1400.00 -10 25 12-NOV-85 25 05-APR-83 25 08-MAY-80 25 17-JUL-85 25 3-JUN-84 25 21-DEC-85 25 16-FEB-84 25 16-FEB-84 25 16-FEB-84

Question 5: Loading into multiple tables during an import using the WHEN keyword. The control
file loads two different tables making three passes at one of them. Note the problem with the Doolittle record and how it is handled.
1234 1234 2664 5321 2134 2414 6542 2849 4532 1244 123 1453 BAKER JOKER YOUNG OTOOLE FARMER LITTLE LEE EDDS PERKINS HUNT DOOLITTLE MACDONALD 10 10 20 10 20 20 10 xx 10 11 12 25 9999 9999 2893 9999 4555 5634 4532 4555 9999 3452 9940 5532 101 777 425 321 236 236 102 102 103 888 999 abc 102 55 40 456 456 40 321 14 294 40

40 665 133 456 132 200

Question 6: Using a built-in function to modify data during loading. Convert to upper case for
last_name and lower case for first_name for funcdemo.
Poder Tanel

Wilton Jeremiah

Question 7: Loading multiple files into multiple tables in a single control file. Note the use of the
WHEN keyword.

Datafile1: 2021234515 2022345610 4041234510 Datafile 2: 2021234515 2022345610 4041234510 Question 8: Loading XML
BEGINDATA <?xml version="1.0"?> <purchaseOrder xmlns="http://www.oracle.com/PO" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/PO http://www.oracle.com/scha0/po1.xsd" orderDate="1999-10-20">

<shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo>

<billTo country="US"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip> </billTo>

<comment>Hurry, my lawn is going wild!</comment>

<items> <item partNum="872-AA"> <productName>Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA"> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder>

Sol Hint: XMLTYPE (xmldata) FIELDS

(xmldata CHAR(2000)) BEGINDATA

Question 9:

Adding a CLOB column called resume to the table emp Using a filler field (res_file) Loading multiple LOBFILEs into the emp table
Resume for Mary Clark

>>ulcase91.dat<< Career Objective: Manage a sales team with consistent record-breaking performance. Education: BA Business University of Iowa 1992 Experience: 1992-1994 - Sales Support at MicroSales Inc. Won "Best Sales Support" award in 1993 and 1994 1994-Present - Sales Manager at MicroSales Inc. Most sales in mid-South division for 2 years >>ulcase92.dat<< Resume for Monica King Career Objective: President of large computer services company Education: BA English Literature Bennington, 1985 Experience: 1985-1986 - Mailroom at New World Services 1986-1987 - Secretary for sales management at New World Services 1988-1989 - Sales support at New World Services 1990-1992 - Salesman at New World Services 1993-1994 - Sales Manager at New World Services 1995 - Vice President of Sales and Marketing at New World Services 1996-Present - President of New World Services >>ulcase93.dat<< Resume for Dan Miller Career Objective: Work as a sales support specialist for a services company Education: Plainview High School, 1996 Experience: 1996 - Present: Mail room clerk at New World Services >>ulcase94.dat<< Resume for Alyson Jones Career Objective: Work in senior sales management for a vibrant and growing company Education: BA Philosophy Howard Univerity 1993 Experience: 1993 - Sales Support for New World Services

1994-1995 - Salesman for New World Services. Led in US sales in both 1994 and 1995. 1996 - present - Sales Manager New World Services. My sales team has beat its quota by at least 15% each year. >>ulcase95.dat<< Resume for David Allen Career Objective: Senior Sales man for agressive Services company Education: BS Business Administration, Weber State 1994 Experience: 1993-1994 - Sales Support New World Services 1994-present - Salesman at New World Service. Won sales award for exceeding sales quota by over 20% in 1995, 1996. >>ulcase96.dat<< Resume for Tom Martin Career Objective: Salesman for a computing service company Education: 1988 - BA Mathematics, University of the North Experience: 1988-1992 Sales Support, New World Services 1993-present Salesman New World Services
Sol Hint: 1) res_file FILLER CHAR, 2) "RESUME" LOBFILE (res_file) TERMINATED BY EOF NULLIF res_file = 'NONE' )

Question10:
An example of using a built-in function, in this case DECODE, to modify data during loading.Use Table 9 for this.

hello,"" goodbye,"" this is a test,"" hello,""


Solution Hint: ( fld1, fld2 "DECODE(:fld1, 'hello', 'hi', :fld1, 'yes')" )

Vous aimerez peut-être aussi