Introduction to BLOB fields in Oracle databases

Source: Internet
Author: User

We all know that Blob in the Oracle database is a special field, which has better performance than the long field. Its main function is to save binary data such as images. The following describes the main content of the article.

Writing Blob fields is very different from writing other types of fields. Because Blob itself has a cursor, you must use cursor to operate blob. Therefore, before writing Blob, you must obtain the cursor to write data. How can you obtain the Blob cursor?

This requires you to insert an empty blob first, which will create a blob cursor, and then you can query the cursor of the empty blob using select. In this way, you can perform two steps, you can get the blob cursor to write blob data.

Example:

Oracle series: LOB large object processing

It is mainly used to store database fields with a large amount of data. It can store up to 4 GB of unstructured data.

This section describes the storage of character type and binary file type LOB data, and separately introduces the storage of binary type LOB data.

1. LOB data type classification in Oracle databases

1. Data Types:

① Character type:

CLOB: stores a large amount of single-byte character data.

NLOB: stores fixed-width, multi-byte character data.

② Binary type:

BLOB: stores large unstructured binary data.

③ Binary file type:

BFILE: stores binary files in operating system files outside the database. Path for storing files.

2. Storage:

① Stored in the internal tablespace:

CLOB, NLOB, and BLOB

② Point to an external operating system file:

BFILE

Ii. Big Object Data Input

1. Declare the LOB type column

 
 
  1. /*  
  2. conn scott/tiger;  
  3. Create TableSpace ts5_21  
  4. DataFile 'E:\Oracle\ts5_21.dbf'  
  5. Size 5m;  
  6. */  
  7. Create Table tLob (   
  8. no Number(4),  
  9. name VarChar2(10),  
  10. resume CLob,  
  11. photo BLob,  
  12. record BFile  
  13. )  
  14. Lob (resume,photo)Store As ( 

Tablespace ts5_21 -- specify the Tablespace to be stored

Chunk 6 k -- specify the data block size

 
 
  1. Disable Storage In Row   
  2. ); 

2. Insert a large object Column

① Insert common column data first

② When a large object column is encountered, insert a blank constructor.

Role: empty_clob (), empty_nclob ()

Binary: empty_blob ()

Binary file type: The BFileName function points to an external file.

BFileName function:

BFileName ('logical directory name', 'filename ');

The logical directory name can only be in uppercase, because the data dictionary is stored in uppercase. Oracle databases are case sensitive.

During creation, you do not need to point the logical directory of the BFileName function to the physical path. When using this function, you can check whether the two are associated.

Example:

 
 
  1. Insert Into tLob Values(1,'Gene',empty_clob()
    ,empty_blob(),bfilename('MYDIR','IMG_0210.JPG'));  

③ Associate the logical directory with the physical directory. (For binary files)

Grant create any directory permission

Grant create any directory to user name with admin option;

Associate logical directory and physical directory

Local

Create Directory logical Directory name As 'physical Directory of the file ';

Network:

Create Directory logical Directory name As '\ Host Name (IP) \ shared Directory ';

Example:

Create Directory MYDIR As 'e: \ Oracle ';

Insert example:

Insert into tlob values (1, 'gene ', 'clob large object Column

 
 
  1. ',empty_blob(),bfilename('MYDIR','IMG_0210.JPG')); 

The above content is an introduction to the operations and performance problems of BLOB data in Oracle databases. I hope you will gain some benefits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.