Detailed anatomy of the Oracle Raw type

Source: Internet
Author: User

The following articles mainly explain the Oracle Raw type in detail. We first talk about the concept of RAW, which is similar to CHAR in that aspect, the declared method is RAW (L). It takes L as the length, and the relevant bytes as the unit. It 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.

Table creation:

 
 
  1. create table raw_test (id number, raw_date raw(10)); 

Insert raw data:

 
 
  1. insert into raw_test values (1, hextoraw('ff'));  
  2. insert into raw_test values (utl_raw.cast_to_raw('051'));  

Delete A table:

 
 
  1. 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 Oracle RAW fields.

You can use the dump function to query the Storage conditions:

 
 
  1. 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 GB2312.

 
 
  1. Insert into cmpp_submit (dest_terminal_id, msg_content)
    Values ('123', UTL_RAW.CAST_TO_RAW ('Hello! '));

2. UTL_RAW.CAST_TO_VARCHAR2

This function is generally GB2312 according to the default character set, and converts RAW to VARCHAR2.

 
 
  1. 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.

Oracle internal definition is:

 
 
  1. struct { ub2 len; char arr[n] } 

The internal ORACLE definition of VARRAW is:

 
 
  1. struct { ub2 len; unsigned char arr[n] }  

Related Article

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.