Raw type in Oracle

Source: Internet
Author: User
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. LONGRAW, similar to LO

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 LO

RAW, similar to CHAR, is declared in RAW (L), L is the length, in bytes, as the maximum database column 2000, as the maximum variable 32767 bytes.
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.
Table creation:
Create table raw_test (id number, raw_date raw (10 ));
Insert raw data:
Insert into raw_test values (1, hextoraw ('ff '));
Insert into raw_test values (utl_raw.cast_to_raw ('051 '));
Delete A table:
Drop table raw_test;
When HEXTORAW is used, the data in the string is treated as a hexadecimal number. When UTL_RAW.CAST_TO_RAW is used, the ASCII code of each character in the string is directly stored in RAW fields.

You can use the dump function to query the Storage conditions:
Select id, raw_date, dump (raw_date, 16) dump_raw from raw_test;

Two common conversion functions of RAW and Varchar2 in Oracle
1. UTL_RAW.CAST_TO_RAW
This function converts the VARCHAR2 string to RAW according to the default character set (generally GB2312.
Insert into cmpp_submit (dest_terminal_id, msg_content) values ('20170101', UTL_RAW.CAST_TO_RAW ('Hello! '));
2. UTL_RAW.CAST_TO_VARCHAR2
This function combines the default character set (generally GB2312) and converts RAW to VARCHAR2.
Select UTL_RAW.CAST_TO_VARCHAR2 (msg_content) from cmpp_deliver;

In fact, RAW and VARCHAR are similar, but the binary values stored in RAW are not automatically converted into character sets at any time. This is a difference between RAW and VARCHAR, RAW is only an external type, and its internal storage is VARRAW.
The internal Oracle definition of VARCHAR is: struct {ub2 len; char arr [n]}
VARRAW's ORACLE internal definition is: struct {ub2 len; unsigned char arr [n]}

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.