Oracle raw Datatype

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

Introduction to Oracle raw Datatype

The RAW datatype in Oracle 21c is a variable-length binary data type used to store binary data. It is often used to store binary data that cannot be easily converted into a character format, such as binary files or digital certificates.

Also, check: Char Datatype in Oracle Database

Oracle raw datatype Syntax

The syntax for declaring a column of raw datatype in Oracle 21c is as follows:

column_name RAW(size);

where column_name is the name of the column being declared as the RAW datatype and size is the maximum number of bytes allowed in the RAW data. The size can range from 0 to 32767.

Read: Oracle Blob Datatype

Oracle raw datatype Example

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

CREATE TABLE binary_data (id NUMBER, binary_file RAW(4000));

In this example, we create a table called “binary_data” with two columns: “id” and “binary_file”. The “binary_file” column is of type RAW and can store binary data up to a maximum size of 4000 bytes.

Now we will insert the data into a following given table

INSERT INTO binary_data (id, binary_file) 
VALUES (1, hextoraw('FFD8FFE0'));

select* from binary_data;
Using raw datatype in oracle 21c
Using raw datatype in oracle 21c

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

Using raw datatype in sql developer tool
Using raw datatype in SQL developer tool

In this given example, we create a table called “Customers” with two columns: “cust_id” and “product_details”. The “product_details” column is of type RAW and can store binary data up to a maximum size of 3000 bytes.

INSERT INTO customers (cust_id, product_details) 
VALUES (672, hextoraw('74a5cfe'));

select* from customers;
insert values into a customers
insert values into a customers

Also, check: Clob Datatype in Oracle Database

Advantages of oracle raw datatype

  • Storage efficiency: A RAW datatype is a good option for data storage because it uses the least amount of space to store binary data.
  • Processing binary data quickly is made possible by the RAW datatype when compared to other datatypes like BLOB, CLOB, etc.
  • Interoperability with other systems: The RAW datatype is a compatible choice for integrating data from many systems since it can be used to store binary data obtained from external systems.
  • Little overhead: The RAW datatype is a practical option for storing binary data because it doesn’t require character set translation or validation.
  • Simple to use and does not require additional handling, the RAW datatype is a straightforward solution for storing data.

Conclusion

So, in this Oracle tutorial, we understood how to define and use the 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.