Using the Oracle Bulk Loader-1

Using the Bulk Loader in ORACLE

The ORACLE SQL* Loader is a facility that allows you to populate database tables from flat files. To use this facility, you need to prepare (i) your flat file(s), and (ii) a control file that tells ORACLE how to "map" fields of the flat file to columns of an RDBMS table. Furthermore, the data can also be appended at the end of the control file, making the process much simpler. Most probably, you will prepare one control file for each table that you want to bulk load to. Notice that preparing the data is part of your assignment. There are no "tools" for this. You either create them from some C program (example) that generates the data and outputs it into a file, or if you are lucky, you might find a web page that already has the data that you need with minimal text processing.

Reena Khosla has prepared the following hints and steps to help in bulk loading.
  • Preparing the Control File: You can create one using a text editor such as notepad and then save it with a ".ctl" extension. The instructions on how to make the control file can be found at the location:

    file:////eulalia/www/oracle/database.804/a58244/ch04.htm#534.

    This has several sample control files that you can use to experiment with this facility. Try experimenting with the control file specified in the first example. Notice that if you use "INFILE *" as is specified in that control file then you need to specify the data in the control file itself. Apparently, if you use "INFILE filename" then you can specify the file in which your data is located. (we haven't experimented with this).

    Important: Make sure that you have a carriage return after the last tuple in your data file. Otherwise the loader doesn't like it and fails to insert the last tuple. After you have your control file and data file ready, login to ORACLE, create the table with normal SQL DDL commands, and then invoke the SQL bulk loader.

  • Invoking the Loader: Goto the DOS prompt and cd to "F:\software\orant\bin\". From there, invoke the SQL LOADER by typing the following:

    sqlldr80 userid=pid/password@hoststring
    control=drive:\path\controlfilename.ctl log=drive:\path\logfilename.log
    The hoststring in our case is "default". Yes, the password has to be typed on the command line! :-) (We haven't found a way around this). If the command executed successfully, go back to ORACLE and do a "SELECT *" on that table and make sure that the data is indeed there!

  • Committing Transactions: We are getting ahead of the lectures here, but this is needed to understand how ORACLE does things.

    • We have experienced problems when we try to bulk load into a table that already has data. This is because this is no longer considered an "INPUT" operation, rather an "APPEND" operation. So, if you have problems with this, either look into the manual for "APPEND" or delete all the tuples and load it (via INSERT) again! :-(

    • In addition, notice that changes made to your database via the insert, delete, update commands can be reversed if necessary. Towards this end, ORACLE SQL provides two commands: commit, and rollback. The changes you make on the command line prompt (using insert, delete/update) can be made permanent using the commit statement. Thus, for example if you delete everything from the SQL prompt and then do a SELECT, you might find the table "empty". However, if you try to bulk load, the loader will not allow this. The reason is because what you are seeing on the screen is not "permanent". To make it permanent, type commit and try bulk loading again.

      Similarly, the changes made to the database since the last commit can be reversed by using the rollback statement.

    • Also notice that some commands force a commit even without the user explicitly issuing a commit statement. This is typical of ORACLE DDL commands (and also the bulk loader).

    • When the user exits an SQL session, the system automatically commits all the changes.
  • 你可能感兴趣的:(oracle,sql,Web,dos,Go)