Oracle Long raw Datatype

In this Oracle tutorial, we will learn about the Long raw data in the Oracle database. Also, we will illustrate how to use it to create long raw columns for a table in Oracle.

Oracle Long raw Datatype

Let us start with the introduction, and then move to the other section.

Introduction

In Oracle, binary big objects (BLOBs) of binary data are stored using the Long Raw datatype. Unstructured binary data, such as pictures, audio files, or video files, are stored there.

In contrast to the BLOB datatype, the Long Raw datatype has no size restrictions and can contain a substantial quantity of binary data. Multimedia data is best stored using the Long Raw datatype.

Because LONG RAW has a less storage capacity than other data types like BLOB, it is rarely employed in modern database systems.

Also, check: How to create a user in Oracle

Syntax

The syntax for declaring a Long Raw datatype in Oracle 21c is as follows:

column_name LONG RAW;

Where column_name is the column’s name being declared as the LONG RAW datatype and size is the maximum number of bytes allowed in the LONG RAW data. The size of a LONG RAW data type in Oracle 21c can range from 0 to 2^32-1 bytes.

Read: How to copy a table in Oracle

Example

An example of using the Long raw datatype in Oracle 21c is as follows:

CREATE TABLE my_table (
  id NUMBER,
  data LONG RAW
);

In this example, a table named my_table has two columns, id and data. The data column is of type LONGRAW, which can store binary data of variable length.

You can insert data into this table using the following statement:

INSERT INTO my_table (id, data)
VALUES (456, HEXTORAW('F1A5'));

select * from my_table;

In this example, the id column is set to 456 and the data column is set to binary F1A5 in hexadecimal format. The HEXTORAW function converts the hexadecimal string to a RAW data type.

oracle long raw

Also, check: Oracle Varchar2 Datatype

Example:

Now we will use the Long raw datatype in a SQL developer tool using Oracle 21c.

In this given example, we create a table called “Employees” with two columns: “emp_id” and “emp_data”. The “emp_data” column is of type LONG RAW.

oracle long raw to varchar2

Now we will insert the values into the following given table

INSERT INTO employees (emp_id, emp_data)
VALUES (864, hextoraw('FFD8FFE0'));

select * from employees;
oracle long raw datatype

Advantages

The Long Raw datatype in Oracle stores large binary data, such as audio or video files or large binary objects (BLOBs). The main advantage of using Long Raw is its ability to store large amounts of binary data without additional storage management or compression.

This makes it ideal for storing unstructured or semi-structured data, as well as for preserving data integrity.

Another advantage of using Long Raw is its compatibility with other Oracle datatypes. For example, a Long Raw column can be directly linked to other tables, allowing data to be retrieved and processed efficiently.

Additionally, Long Raw is fully supported by Oracle’s programming language, making it easy to write procedures and functions that operate on Long Raw data.

Features

  • Small storage: Because a REAL data type only requires 4 bytes of storage, it is a good choice for large databases that require a lot of data.
  • High accuracy: The REAL data type offers a high degree of precision and is suited for scientific or financial applications where precision is essential.
  • Speed: The REAL data type is built for rapid processing, making it a good fit for high-performance computing applications.
  • Because it is compatible with so many different programming languages, a REAL data type is a fantastic choice for developers who need to work with various frameworks or languages.
  • Usability: The REAL data type is easy to use, which is highly useful for developers unfamiliar with Oracle databases.

Conclusion:

So, in this Oracle tutorial, we understood how to define and use the Long raw Datatype in Oracle Database. And we have also covered a few sample examples related to it.

Also, take a look at some more Oracle tutorials.

Top 200 SQL Server Interview Questions and Answers

Free PDF On Top 200 SQL Server Interview Questions And Answers

Download A 40 pages PDF And Learn Now.