What Is Raw Data Type in PL SQL?


Heather Bennett

In PL/SQL, the raw data type is used to store binary data or byte strings. It is a fixed-length data type that can hold up to 32,767 bytes. Raw data type is commonly used to store images, audio files, video files, and other binary data in the database.

Working with Raw Data Type

When working with raw data type in PL/SQL, it’s important to understand how to handle and manipulate the binary data. Here are some key points to keep in mind:

1. Storing Raw Data

To store raw data in a table column, you need to define the column as RAW(n), where n represents the number of bytes required to store the binary data. For example:

CREATE TABLE my_table (
    id NUMBER,
    image_data RAW(2000)

In this example, we have defined a column called “image_data” of type RAW(2000) which can hold up to 2000 bytes of binary data.

2. Inserting Raw Data

When inserting raw data into a table, you can use the HEXTORAW function to convert a hexadecimal string into raw format. For example:

INSERT INTO my_table (id, image_data)
VALUES (1, HEXTORAW('FFD8FFE000104A46494600010100000100010000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C2132323232323232323232323232323232323232323232323232323'));

This example inserts a hexadecimal string representing an image into the “image_data” column. The HEXTORAW function converts the string into raw format before inserting it into the table.

3. Retrieving Raw Data

To retrieve raw data from a table, you can use the RAWTOHEX function to convert the raw data into a hexadecimal string. For example:

SELECT id, RAWTOHEX(image_data) AS hex_data
FROM my_table;

This query retrieves the “id” and “image_data” columns from the “my_table” table. The RAWTOHEX function converts the raw data into a hexadecimal string, which can be easily displayed or processed.

Benefits of Raw Data Type

The raw data type in PL/SQL offers several benefits:

  • Efficient Storage: Raw data type stores binary data in its original form without any additional processing or conversions, resulting in efficient storage utilization.
  • Faster Retrieval: Since raw data is stored as-is, it can be retrieved quickly without any need for additional processing or decoding.
  • Versatility: Raw data type allows you to store any kind of binary data, making it suitable for a wide range of applications such as multimedia storage and document management systems.

In conclusion, the raw data type in PL/SQL provides a convenient and efficient way to store and manipulate binary data. By understanding how to work with raw data, you can effectively manage and utilize binary information in your applications.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy