Preview

Saving File in Oracle Database

Good Essays
Open Document
Open Document
370 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Saving File in Oracle Database
Sometimes we have to save image, any type of multimedia file or text file in Oracle database from client. In web application client must upload the file in web server or any other machine. But web server can access that directory where the files are uploaded. To complete the operation we can use Oracle Blob data type, Oracle directory and with a procedure.

Implementation:
Suppose we have a table name ImageTable. The table should be like this.
CREATE TABLE ImageTable
(
ID NUMBER,
FILENAME VARCHAR2(3000 BYTE),
DATA BLOB,
CONSTRAINT ImageTable_ID_PK PRIMARY KEY (ID)
);

Here filename is unique. Also we have a sequence for the table name “imagetable_seq”. Suppose the files are uploaded in “C:\pics” directory in web server. If the web server and database server in the same machine then there is no problem for the database server to access that files to operate.
At first we should create a directory where the file are uploaded or stored like we stored in “C:\pics” in server machine. So our script should be like this: create or replace directory Image_FILES as ‘C:/pics’;
Note that here Oracle use forward slash. We create a directory in application server or database server. In our case both are same machine. So there is no problem to access file for the Oracle Database server. After that we should create a oracle procedure name “saveImage” which script should be like this:

create or replace procedure saveImage(p_filename varchar2,seq_Id out number) as l_clob blob; l_bfile bfile;

begin delete from ImageTable where filename = p_filename; commit; insert into ImageTable (ID,fileName,data) values (imagebytes_seq.NEXTVAL, p_filename, empty_blob()) returning data into l_clob; l_bfile := bfilename( ‘Image_FILES’, p_filename ); dbms_lob.fileopen( l_bfile,DBMS_LOB.LOB_READONLY ); dbms_lob.loadfromfile( l_clob, l_bfile,dbms_lob.getlength( l_bfile ) ); select imagebytes_seq.CurrVal into seq_Id from dual; update imagebytes set data =l_clob where

You May Also Find These Documents Helpful

  • Good Essays

    Nt1330 Unit 6 Lab Report

    • 1088 Words
    • 5 Pages

    1. Create a new user called fileShare with password of p@ssw0rd. Set the account so it does not have to change the password as shown below:…

    • 1088 Words
    • 5 Pages
    Good Essays
  • Good Essays

    This software is going to have a web server which will be connected to whenever any web service is needed. This server is also going to contain the database. Thus in needs for data also, system will communicate with this server. This communication is capable with the help of JDBC. The data will be synchronized and consistent data will be kept in the server.…

    • 612 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Nt1330 Unit 1 Study Guide

    • 1178 Words
    • 5 Pages

    A Database is generally used for storing data in a structured way in an efficient manner for insert, update and retrieval of data in well defined formats. On the other hand, in file system the data stored in unstructured manner with an unrelated data.…

    • 1178 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Comp230 Week 5

    • 1799 Words
    • 8 Pages

    strComputer = ". " Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\CIMV2") Set colOperatingSystems = objWMIService.…

    • 1799 Words
    • 8 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Week 3 Ilab

    • 367 Words
    • 2 Pages

    == = Set fso = CreateObject("Scripting. FileSystemObject") Set…

    • 367 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Data Comm

    • 501 Words
    • 3 Pages

    3. List some advantages of mapping a directory located on a server to a workstation.…

    • 501 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    12

    • 389 Words
    • 2 Pages

    3. Save your image with an appropriate name to reflect your vision of what the abstract image…

    • 389 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    JavaScript Arrays Lab

    • 531 Words
    • 4 Pages

    The Images folder contains 12 images that represent the Chinese Zodiac animals. Notice that some images are in GIF format and others are in PNG format.…

    • 531 Words
    • 4 Pages
    Satisfactory Essays
  • Powerful Essays

    The Maze Runner

    • 106030 Words
    • 425 Pages

    The link ed image cannot be display ed. The file may hav e been mov ed, renamed, or deleted. Verify that the link points to the correct file and location.…

    • 106030 Words
    • 425 Pages
    Powerful Essays
  • Good Essays

    Delegation

    • 655 Words
    • 3 Pages

    If there are images in this attachment, they will not be displayed. Download the original attachment[->0]…

    • 655 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Ghost Multicasting

    • 656 Words
    • 3 Pages

    1. Prepare a boot disk that includes and loads the necessary network drivers and maps the disk images directory from the network.…

    • 656 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Information stored in a mass storage system is conceptually grouped into large units called files. A typical file may consist of a complete text document, a photograph, a program, a music recording, or a collection of data about the employees in a company. Mass storage devices dictate that these files be stored and retrieved in smaller, multiple byte units. For example, a file stored on a magnetic disk must be manipulated by sectors, each of which is a fixed predetermined size. A block of data conforming to the specific characteristics of a storage device is called a physical record. Thus, a large file stored in mass storage will typically consist of many physical records. In contrast to this division into physical records, a file often has natural divisions determined by the information represented. For example, a file containing information regarding a company’s employees would consist of multiple units, each consisting of the information about one employee. Or, a file containing a text document would consist of paragraphs or pages. These naturally occurring blocks of data are called logical records. Logical records often consist of smaller units called fields. For example, a logical record containing information about an employee would probably consist of fields such as name, address, employee identification number, etc. Sometimes each logical record within a file is uniquely identified by means of a particular field within the record (perhaps an employee’s identification number, a part number, or a catalogue item number). Such an identifying field is called a key field. The value held in a key field is called a key.…

    • 487 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    D. The number of columns and data types must be identical for all SELECT statements in the…

    • 12451 Words
    • 50 Pages
    Powerful Essays
  • Satisfactory Essays

    File Management

    • 372 Words
    • 2 Pages

    The first version of UNIX had a file access scheme where the users where assigned a UID known as a user identification number. The user was also apart many groups but had a main group. The groups where identified by a group id, so as files were created they were assigned to a user that had that particular id attached to the user.…

    • 372 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    File Management

    • 803 Words
    • 4 Pages

    There are issues that arise concerning file sharing in a multiuser system, and that is access rights and the management of simultaneous access. Access rights to a file is granted unique users whether singular or grouped. A flexible tool is provided to allow extensive file sharing among the users while providing a number of options so that certain access can be harnessed or controlled (Stallings , 2012).…

    • 803 Words
    • 4 Pages
    Good Essays