Home  >  Article  >  Database  >  Oracle中的Raw类型解释

Oracle中的Raw类型解释

WBOY
WBOYOriginal
2016-06-07 16:55:422204browse

RAW,类似于CHAR,声明方式RAW(L),L为长度,以字节为单位,作为数据库列最大2000,作为变量最大32767字节。 LONG RAW,类似于LO

RAW,类似于CHAR,声明方式RAW(L),L为长度,,以字节为单位,作为数据库列最大2000,作为变量最大32767字节。
LONG RAW,类似于LONG,作为数据库列最大存储2G字节的数据,作为变量最大32760字节
建表操作:
create table raw_test (id number, raw_date raw(10));
插入raw数据操作:
insert into raw_test values (1, hextoraw('ff'));
insert into raw_test values (utl_raw.cast_to_raw('051'));
删除表操作:
drop table raw_test;
当使用HEXTORAW时,会把字符串中数据当作16进制数。而使用UTL_RAW.CAST_TO_RAW时,直接把字符串中每个字符的ASCII码存放到RAW类型的字段中.

可以使用dump函数,查询存储情况:
select id,raw_date, dump(raw_date, 16) dump_raw from raw_test;

Oracle中RAW和Varchar2常用的两个转换函数                                  
1. UTL_RAW.CAST_TO_RAW
该函数按照缺省字符集(一般为GB2312),将VARCHAR2字符串转换为RAW。
insert into cmpp_submit (dest_terminal_id,msg_content) values('13001081371',UTL_RAW.CAST_TO_RAW('您好!'));
2. UTL_RAW.CAST_TO_VARCHAR2
该函数按照缺省字符集合(一般为GB2312),将RAW转换为VARCHAR2。
select UTL_RAW.CAST_TO_VARCHAR2(msg_content) from cmpp_deliver;

其实RAW和VARCHAR是类似的,只是存储在RAW里的是二进制值,在任何时候不会做自动的字符集转换,这是RAW和VARCHAR的不同,RAW只是一种外部类型,其内部存储是VARRAW
VARCHAR的Oracle内部定义是:struct { ub2 len; char arr[n] }
VARRAW的ORACLE内部定义是: struct { ub2 len; unsigned char arr[n] }

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn