SQL*Loader Tutorial ------------------- Setup Information ----------------- In order to run the sample SQL*Loader files, as well as the previous PL/SQL and future Embedded C examples, you need to load the sample database. This can be done by running sqlplus and then typing: start /home/1/oracle/sql/plsql/tutorial.sql When you are done running with the tutorial database, it is a good idea to drop all the data and tables from the tutorial database. To do this, run sqlplus and type: start /home/1/oracle/sql/plsql/droptutorial.sql Also, in case you decide that you no longer need the data from the complete.ref file, this can be easily dropped by running sqlplus and typing: start /home/1/oracle/sql/dropcomplete.sql If you drop the data from complete.ref and wish to reload it, you can do this by typing: start /home/1/oracle/sql/complete.ref It is a good idea not to waste space with data that you no longer use. Tutorial -------- NOTE: For the SQL*Loader example that follows, it is necessary that you have included that data and tables found in the tutorial.sql file explained above. Suppose you have the entity country which has three attributes, cname, pop, and cont. (You should recognize this from the exam.) Let's say the data you have is in a table like the one below. You don't want to have to enter every one of those lines with a cumbersome command like: INSERT INTO country VALUES ('Afghanistan', 21251821, 'Asia'); ...especially not when all the data is already typed. That's what the SQL*Loader is for. Sample Data : country.dat ------------------------- Afghanistan 21251821 Asia Antarctica 4115 Anartctica Albania 3413904 Europe Algeria 28539321 Africa Australia 18322231 Australia Belize 214061 North America Benin 5522677 Africa Bolivia 7896254 South America Brazil 160737489 South America Canada 28434545 North America China 1203097268 Asia Columbia 36200251 South America SQL*Loader takes data, as well as a control file, to insert data into the table for you. Control File : country.ctl -------------------------- load data infile 'country.dat' into table country (cname position (01:16) char, pop position (17:32), cont position (33:46) char) This control file says that we want to load data from the file country.dat into the table country using columns that we have already set up. For example, from column 1 to column 16, we take that information and use it as the country name. These files are available as /home/1/oracle/sql/loader/country.dat /home/1/oracle/sql/loader/country.ctl To run SQL*Loader, issue the command: sqlload For example, sqlload richardw country.ctl To run these examples, you should copy this information to the directory you are going to run from. When you run sqlload, it will prompt you for your Oracle password.