Introduction to Oracle raw Data Types

Source: Internet
Author: User

This type has never been met before. I learned that someone asked me yesterday and I only studied it.
Later, we found that the Oracle Data dictionary used this data type in many places, such as the addr field of v $ process.
What type is this? I have read the materials and said it is used to store binary data. But what are the advantages of such storage? Google has a lot of cases, and it is easy to understand the descriptions:
When RAW data is transmitted between computers in the network or RAW data is moved from one database to another using the Oracle utility, the Oracle server does not perform Character Set conversion. The size of the number of bytes required to store the actual column value varies with the size of each line, up to 2,000 bytes.
It is possible that such data types will increase database efficiency, and the possibility of data inconsistency due to different character sets is also ruled out here.
This field does not seem to be used in actual use.
The raw type introduces the user's blog here:
RAW, similar to CHAR, is declared as RAW (L). L is the length, in bytes, and serves as the maximum 2000 bytes of the database column and the maximum 32767 bytes of the variable.
Long raw, similar to LONG, is used to store up to 2G bytes of data as a database column and up to 32760 bytes as a variable.

Test:

SQL> create table datatype_test_raw (paddr raw (8 ));

 
Table created
 
SQL> insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('this is a raw type test! '));
 
Insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('this is a raw type test! '))
 
ORA-01401: inserted value too large for column
 
SQL> alter table datatype_test_raw modify paddr raw (20 );
 
Table altered
 
SQL> insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('this is a raw type test! '));
 
Insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('this is a raw type test! '))
 
ORA-01401: inserted value too large for column
 
SQL> insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('this is a raw test! '));
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select * from datatype_test_raw;
 
PADDR
----------------------------------------
54686973206973206120726177207465737421
 
SQL> select utl_raw.cast_to_varchar2 (paddr) from datatype_test_raw;
 
UTL_RAW.CAST_TO_VARCHAR2 (PADDR
--------------------------------------------------------------------------------
This is a raw test!
 
SQL> insert into datatype_test_raw (paddr) values (utl_raw.cast_to_raw ('Chinese test '));
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select utl_raw.cast_to_varchar2 (paddr) from datatype_test_raw;
 
UTL_RAW.CAST_TO_VARCHAR2 (PADDR
--------------------------------------------------------------------------------
This is a raw test!
Chinese test
 
SQL> select paddr, utl_raw.cast_to_varchar2 (paddr) from datatype_test_raw;
 
PADDR UTL_RAW.CAST_TO_VARCHAR2 (PADDR
-------------------------------------------------------------------------------------------
54686973206973206120726177207465737421 This is a raw test!
D6D0CEC4B2E2CAD4 Chinese test
 
Two functions are used here:
Utl_raw.cast_to_raw ([varchar2]); -- convert varchar2 to raw type
Utl_raw.cast_to_varchar2 ([raw]); -- convert raw to varchar2.
Here, the varchar2 character set is generally GB2312.

In addition:
Usage of several other functions in the utl_raw package:
Utl_raw.cast_from_number ([number]);
Utl_raw.cast_to_number ([number]);
Bit operation:
Utl_raw.bit_or ();
Utl_raw.bit_and ();
Utl_raw.bit_xor ();

There are also conversion functions:
Hextoraw (); -- converts the hexadecimal number to raw
The introduction of raw and utl_raw ends here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.