This action might not be possible to undo. Are you sure you want to continue?
For example, if you have a table in FOXPRO, ACCESS or SYBASE or any other third party database, you can use SQL Loader to load the data into Oracle Tables. SQL Loader will only read the data from Flat files. So If you want to load the data from Foxpro or any other database, you have to first convert that data into Delimited Format flat file or Fixed length format flat file, and then use SQL loader to load the data into Oracle. Following is procedure to load the data from Third Party Database into Oracle using SQL Loader. 1. Convert the Data into Flat file using third party database command. 2. Create the Table Structure in Oracle Database using appropriate datatypes 3. Write a Control File, describing how to interpret the flat file and options to load the data. 4. Execute SQL Loader utility specifying the control file in the command line argument To understand it better let us see the following case study.
CASE STUDY (Loading Data from MS-ACCESS to Oracle)
Suppose you have a table in MS-ACCESS by name EMP, running under Windows O/S, with the following structure EMPNO NAME SAL JDATE INTEGER TEXT(50) CURRENCY DATE
This table contains some 10,000 rows. Now you want to load the data from this table into an Oracle Table. Oracle Database is running in LINUX O/S.
Start MS-Access and convert the table into comma delimited flat (popularly known as csv) , by clicking on File/Save As menu. Let the delimited file name be emp.csv
For example.100.csv File transferred in 0. FTP>bye Good-Bye 2. At the command prompt type FTP followed by IP address of the server running Oracle.200. Go to Command Prompt in windows b.1. Supply a valid username and password of Oracle User in Linux For example:C:\>ftp 200. . create a table like this $sqlplus scott/tiger SQL>CREATE TABLE emp (empno number(5). FTP will then prompt you for username and password to connect to the Linux Server.111 Name: oracle Password:oracle FTP> c.csv remote-file:/u01/oracle/emp. Now after the file is transferred quit the FTP utility by typing bye command. Now transfer this file to Linux Server using FTP command a. FTP>put Local file:C:\>emp. Now come the Linux Machine and create a table in Oracle with the same structure as in MS-ACCESS by taking appropriate datatypes.29 Seconds FTP> d. Now give PUT command to transfer file from current Windows machine to Linux machine.
then bad records found during loading will be stored in this file. INSERT : Loads rows only if the target table is empty . 3. you have to write a control file describing the actions which SQL Loader should do.dsc‟ INSERT INTO TABLE emp FIELDS TERMINATED BY “. 4. 2.jdate date „mm/dd/yyyy‟) Notes: (Do not write the line numbers. they are meant for explanation purpose) 1. The INFILE option specifies where the input file is located Specifying BADFILE is optional. 3. After creating the table. If you specify.” OPTIONALLY ENCLOSED BY „”‟ TRAILING NULLCOLS (empno. 5. then records which do not meet a WHEN condition will be written to this file.name.2). You can use any text editor to write the control file.name varchar2(50). Specifying DISCARDFILE is optional. sal number(10. If you specify. The LOAD DATA statement is required at the beginning of the control file. jdate date).ctl 1 2 3 4 5 6 7 LOAD DATA INFILE BADFILE DISCARDFILE „/u01/oracle/emp. You can use any of the following loading option 1.csv‟ „/u01/oracle/emp.sal.bad‟ „/u01/oracle/emp. Now let us write a controlfile for our case study $vi emp.
You have to view this file for any errors encountered while running SQLLoader. In this line specify the columns of the target table. colon “:”.” so we have specified “. APPEND: Load rows if the target table is empty or not. REPLACE: First deletes all the rows in the existing table and then. TRUNCATE: First truncates the table and then load rows. Since in our case the fields are separated by “. TRAILING NULLCOLS means if the last column is null then treat this as null value.50 5500.00 30 1400.75 1600. how many were rejected and how much time is taken to load the rows and etc.00 30 . The LOG option of sqlldr specifies where the log file of this sql loader session should be created. 4. 6. The log file contains all actions which SQL loader has performed i.00 1312. Note how do you specify format for Date columns 4. otherwise. 7. pipe “|” etc. CASE STUDY (Loading Data from Fixed Length file into Oracle) Suppose we have a fixed length format file containing employees data.00 920.e. You can replace this by any char which is used to terminate fields. how many rows were loaded.2.”. 7782 CLARK 7839 KING 7934 MILLER 7566 JONES 7499 ALLEN 7654 MARTIN MANAGER PRESIDENT CLERK MANAGER SALESMAN SALESMAN 7782 7839 7698 7698 7839 2572. 3. load rows. This line indicates how the fields are separated in input file. and wants to load this data into an Oracle table.ctl log=emp.” as the terminating char for fields. as shown below. Some of the popularly use terminating characters are semicolon “.log After you have executed the above command SQL Loader will shows you the output describing how many rows it has loaded. SQL LOADER will treat the record as bad if the last column is null. After you have wrote the control file save it and then. call SQL Loader utility by typing the following command $sqlldr userid=scott/tiger control=emp.00 3123.50 10 10 10 20 300.
2.2). deptno NUMBER(3) ). by any name. NUMBER(5). but should match columns specified in fixed length file. job mgr sal VARCHAR2(10). comm NUMBER(10. SQL> CREATE TABLE emp (empno name VARCHAR2(20).00 30 SOLUTION: Steps :- 1.00 1312. In our case give the following command to create the table. Similarly other columns are also located. 3. Create a table in Oracle.2). now write a control file by using any text editor $vi empfix. for example in our fixed length file. NUMBER(5).50 20 1400. NUMBER(10. After creating the table. employee number is from 1 st position to 4th position.7658 CHAN 7654 MARTIN ANALYST SALESMAN 7566 7698 3450. First Open the file in a text editor and count the length of fields. employee name is from 6th position to 15th position. Job name is from 17th position to 25th position.ctl 1) LOAD DATA .
. The name of the file containing data follows the INFILE parameter. empno. DECIMAL EXTERNAL) identify the datatype of data fields in the file. The LOAD DATA statement is required at the beginning of the control file. name.2) 3) INFILE '/u01/oracle/fix. name job mgr EXTERNAL. 4. The INTO TABLE statement is required to identify the table to be loaded into. comm EXTERNAL. The datatypes (INTEGER EXTERNAL. job. 5. 3. sal EXTERNAL.dat' INTO TABLE emp POSITION(01:04) POSITION(06:15) POSITION(17:25) POSITION(27:30) POSITION(32:39) POSITION(41:48) POSITION(50:51) INTEGER CHAR. CHAR. 5) deptno EXTERNAL) Notes: (Do not write the line numbers. Note that the set of column specifications is enclosed in parentheses. Lines 4 and 5 identify a column name and the location of the data in the datafile to be loaded into that column. not of corresponding columns in the emp table. CHAR. they are meant for explanation purpose) 1. and so on are names of columns in table emp. INTEGER DECIMAL DECIMAL INTEGER 4) (empno EXTERNAL. 2.
50 3450.ctl .4.ctl log=empfix. After saving the control file now start SQL Loader utility by typing the following command. write a control file as shown below $vi emp_multi. For example. Then.00 30 20 1400. You can also use WHEN condition to load only specified rows which meets a particular condition (only equal to “=” and not equal to “<>” conditions are allowed).00 30 1400. suppose we have a fixed length file as shown below 7782 CLARK 7839 KING 7934 MILLER 7566 JONES 7499 ALLEN 7654 MARTIN 7658 CHAN 7654 MARTIN MANAGER PRESIDENT CLERK MANAGER SALESMAN SALESMAN ANALYST SALESMAN 7782 7839 7698 7698 7566 7698 7839 2572.00 3123.00 1312. Loading Data into Multiple Tables using WHEN condition You can simultaneously load data into multiple tables in the same session. To do this first create the tablesemp1 and emp2 by taking appropriate columns and datatypes.00 30 Now we want to load all the employees whose deptno is 10 into emp1 table and those employees whose deptno is not equal to 10 in emp2 table.00 920.75 1600.log direct=y After you have executed the above command SQL Loader will shows you the output describing how many rows it has loaded.50 5500. $sqlldr userid=scott/tiger control=empfix.00 1312.50 10 10 10 20 300.
emp2 WHEN (deptno<>‟10 „) (empno POSITION(01:04) name job mgr sal comm deptno POSITION(06:15) POSITION(17:25) POSITION(27:30) POSITION(32:39) POSITION(41:48) POSITION(50:51) INTEGER EXTERNAL. CHAR.ctl run sqlldr $sqlldr userid=scott/tiger control=emp_multi. INTEGER EXTERNAL. INTEGER EXTERNAL. CHAR.ctl Conventional Path Load and Direct Path Load.dat‟ append into table scott.Load Data infile „/u01/oracle/empfix. INTEGER EXTERNAL) INTO TABLE scott. SQL Loader can load the data into Oracle database using Conventional Path method or Direct Path method. DECIMAL EXTERNAL. CHAR. CHAR. You can specify the method by using DIRECT command line . DECIMAL EXTERNAL.emp1 WHEN (deptno=‟10 „) (empno POSITION(01:04) name job mgr sal comm deptno POSITION(06:15) POSITION(17:25) POSITION(27:30) POSITION(32:39) POSITION(41:48) POSITION(50:51) INTEGER EXTERNAL. INTEGER EXTERNAL) After saving the file emp_multi. DECIMAL EXTERNAL. DECIMAL EXTERNAL.
this can slow bulk loads dramatically. The Oracle database looks for partially filled blocks and attempts to fill them on each insert. This can slow the load significantly. Loading a parent table together with a child Table Loading BFILE columns . A conventional path load calls Oracle once for each array of rows to process a SQL INSERT statement. A direct path load calls on Oracle to lock tables and indexes at the start of the load and releases them when the load is finished. it competes equally with all other processes for buffer resources.option. Oracle will not use SQL INSERT statement for loading rows. Direct Path In Direct Path Loading. so no reads are needed to find them. During a direct path load. SQL*Loader need not execute any SQL INSERT statements. therefore. If you give DIRECT=TRUE then SQL loader will use Direct Path Loading otherwise. into fresh blocks beyond High Water Mark. passed to Oracle. Although appropriate during normal use. Restrictions on Using Direct Path Loads The following conditions must be satisfied for you to use the direct path load method: Tables are not clustered. instead of using Oracle's buffer cache. it does not scan for free blocks before high water mark. Conventional Path Conventional path load (the default) uses the SQL INSERT statement and a bind array buffer to load data into database tables. the processing load on the Oracle database is reduced. Extra overhead is added as SQL statements are generated. processes perform their own write I/O. When SQL*Loader performs a conventional path load. in datafiles i. if omit this option or specify DIRECT=false. A direct path load uses multiblock asynchronous I/O for writes to the database files. Direct Path load is very fast because Partial blocks are not used. and fewer writes are performed. Tables to be loaded do not have any active transactions pending. and executed. This minimizes contention with other Oracle users. Instead it directly writes the rows. then SQL Loader will use Conventional Path loading method.e.