Explanation of common Oracle Raw types

Source: Internet
Author: User

Today we will mainly introduce you to the interpretation of common Oracle Raw types. We all know RAW, which is very similar to CHAR. We declare it in Oracle RAW (L ), L is the length, in the unit of correlation bytes. It is used as the maximum 2000 bytes of the actual database column and as 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 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 Oracle RAW and Varchar2

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 ('20170101', 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, Oracle RAW and VARCHAR are similar, but the binary values stored in RAW are not automatically converted to 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 Oracle internal definition of VARCHAR is:

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

The internal ORACLE definition of VARRAW is:

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

The above content is the description of Oracle Raw type, and I hope it will help you in this regard.

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.