PL/SQL RAW

The Oracle PL/SQL RAW datatype is a binary data type used to store unstructured binary data. The RAW data type is used to store binary data in the database and can be used to store any type of binary data, including images, audio files, video files, and others.

RAW data is stored in the database in its raw binary format, which makes it a suitable choice for storing binary data that does not need to be processed. Unlike other data types such as VARCHAR2 and NUMBER, the RAW data type does not have a character set or a number format. This means that the binary data is stored in the database exactly as it was received, without any modification or conversion.

The RAW data type can store up to 2000 bytes of binary data. When creating a table with a RAW column, you can specify the maximum size of the binary data that can be stored in that column. The syntax for creating a RAW column is as follows:

CREATE TABLE mytable (
   mycolumn RAW(2000)
);

When you insert binary data into a RAW column, you can use the UTL_RAW.CAST_TO_RAW function to convert the binary data to a RAW value. The following example demonstrates how to insert a binary file into a RAW column:

DECLARE
   l_bfile   BFILE := BFILENAME('MY_DIR', 'myfile');
   l_rawdata RAW(2000);
BEGIN
   DBMS_LOB.OPEN(l_bfile, DBMS_LOB.LOB_READONLY);
   DBMS_LOB.READ(l_bfile, DBMS_LOB.GETLENGTH(l_bfile), 1, l_rawdata);
   DBMS_LOB.CLOSE(l_bfile);

   INSERT INTO mytable (mycolumn)
   VALUES (UTL_RAW.CAST_TO_RAW(l_rawdata));
END;

In conclusion, the Oracle PL/SQL RAW datatype is a useful data type for storing unstructured binary data in the database. It is efficient and straightforward to use, and it allows you to store binary data exactly as it is received, without any modification or conversion.