Previous | Table of Contents | Next

Page 360

Why Use Recursion?

When the need to call the function by itself does not occur more than 10 to 15 times, recursion provides an elegant solution to a problem. However, there are many reasons why you will probably never use recursion:

Review of Large Object Datatypes

Oracle8 added four large object datatypes. These datatypes are summarized in Table 15.2. All these datatypes can store data up to 4 gigabytes. This is more than enough to accommodate such items as sound, pictures, and video in your databases. Of the available large object datatypes, three of them are internal to Oracle, and one is external. External refers to a physical file, for which Oracle stores the filename and file location. Internal objects store a locator in the large object column of the table, which points to the actual location of the data in the table.

Table 15.2. Large object datatypes.

Object Location Description
CLOB Internal Character Large Object—Holds up to 4 gigabytes of single-byte characters
NCLOB Internal National Character Large Object—Holds up to 4 gigabytes of single-byte characters or multibyte characters that conform to the national character set defined by the Oracle8 database
BLOB Internal Binary Large Object—Holds up to 4 gigabytes of "raw" binary data
BFILE External Binary File—Stored as a file accessible by the operating system, which Oracle can access and manipulate

Page 361

Using External Files in Your Oracle8
Database

The BFILE datatype is a large binary object that is external to Oracle. External means that the file is accessible to the operating system and not stored within the Oracle database. The information required to access an external object is the directory object and the filename. Of course, you need to make sure that you have all the privileges associated with accessing the directories and files.

Creating the Directory Object

Before you can access outside files, you need to create a directory object. This object maps a name to a path specified in the CREATE statement. The directory object name can be up to 30 characters, and the filename can be up to 2000 characters maximum.

The Syntax for Creating a Directory Object

CREATE (OR REPLACE) DIRECTORY Directory_Name AS Path

Directory_Name is the name of the directory object you are associating with the path. This directory name will be called by Oracle instead of specifying the actual path. Path is the physical path on the system of any secondary storage devices.

NOTE
For the next several exercises, you will need to create a path called books somewhere on a hard drive to which you have access. Copy all the files from the books subdirectory from the CD-ROM into this subdirectory. You will have a total of nine files in the books subdirectory after the copy process has ended.

Before you can try several of the examples in this book, you will need to create a directory object called books. This object will hold the data and descriptions of future or current books required for purchase by your organization. To create the directory object, execute the code in Listing 15.3.

INPUT
Listing 15.3. Creating the directory object books.

CREATE OR REPLACE DIRECTORY books_Dir AS `C:\BOOKS'
/

Page 362

NOTE
Change the last parameter of the path to correspond to the actual path specified by your operating system, such as /home/users/Atwood/books for UNIX users, to which you created and copied the nine files.

After you have executed the SQL statement, you should see output that states that the directory was created.

Limitations of BFILE

The BFILE datatype does not offer transactional support for COMMIT or ROLLBACK. Also, files are opened as read-only, so you can't write or alter these external files in any manner. Another problem that could occur is a "too many files open" error. In order to avoid this error, you need to edit the INIT.ORA file and change the statement SESSION_MAX_OPEN_FILES=20 to whatever value you require. Also keep in mind any operating system requirements. When you do open files, make sure that you close them; otherwise, they are tracked as opened files even when not in use, and you might get the message "too many files open" when you really are accessing under the limit. This mostly occurs when programs terminate abnormally, and there is nothing in place to close all files when the error occurs.

The DBMS_LOB Package with BFILE

The DBMS_LOB package provided by Oracle allows you to manipulate all types of large objects (LOBs). Because the BFILE datatype is the only external datatype, Oracle provides functions used solely for external LOBs. These are summarized in Table 15.3.

Table 15.3. Functions and procedures used with BFILE.

Function or
Procedure
Accessed
By
Description
BFILENAME BFILE Creates a pointer (locator) in the PL/SQL block, or in the table to the location of the file
COMPARE All LOBs Compares all or part of two LOBs
FILECLOSE BFILE Closes the file associated with the BFILE locator
FILECLOSEALL BFILE Closes all open BFILEs
FILEEXISTS BFILE Checks to see if the file exists where the locator says the file should be located

Previous | Table of Contents | Next

Используются технологии uCoz