UTL_RAW

最近更新时间: 2024-10-17 17:10:00

UTL_RAW 系统包提供用于操作 RAW 数据类型的 SQL 函数。普通的 SQL 函数不在RAW 数据上操作,而 PL 不允许在 RAW 和 CHAR 数据类型之间重载。

存储过程/函数 描述
BIT_AND 对 RAW r1 和 RAW r2 中的值执行按位逻辑“与”,并返回原始的“与”结果。
BIT_COMPLEMENT 对 RAW r 中的值执行按位逻辑“补码”,并返回“补码”结果 RAW。
BIT_OR 对 RAW r1 和 RAW r2 中的值执行按位逻辑“或”,并返回原始的“或”结果。
BIT_XOR 对 RAW r1 和 RAW r2 中的值执行逐位逻辑“异或”,并返回原始的“异或”结果。
CAST_TO_RAW 将 VARCHAR2 值转换为 RAW 值。
CAST_TO_VARCHAR2 将RAW 值转换为 VARCHAR2 值。
COPIES 返回串联在一起的 r 的 n 个副本。
COMPARE 比较 RAW r1 和 RAW r2。
CONCAT 将最多 12 个 RAW 串连到一个 RAW 中。
LENGTH 返回 RAW r 的字节长度。
REVERSE 从端到端反转 RAW r 中的字节序列。
SUBSTR 返回 len 字节数,从 RAW r 的 pos 位开始计算。

示例:

select utl_raw.bit_and('ABC', 'ABC') fromdual;
select utl_raw.bit_and('ABC', '') fromdual;
select utl_raw.bit_and('', 'ABC') fromdual;
select utl_raw.bit_and('', '') from dual;
select utl_raw.bit_and(null, '') from dual;
select utl_raw.bit_and(null, null) fromdual;
select utl_raw.bit_and('f000', 'EE10') fromdual;
select utl_raw.bit_and('000', '111') fromdual;
select utl_raw.bit_and('1111', '111') fromdual;

select utl_raw.bit_or('ABC', 'ABC') fromdual;
select utl_raw.bit_or('ABC', '') from dual;
select utl_raw.bit_or('', 'ABC') from dual;
select utl_raw.bit_or('', '') from dual;
select utl_raw.bit_or(null, '') from dual;
select utl_raw.bit_or(null, null) fromdual;
select utl_raw.bit_or('f000', 'EE10') fromdual;
select utl_raw.bit_or('000', '111') fromdual;
select utl_raw.bit_or('1111', '111') fromdual;

select utl_raw.bit_xor('ABC', 'ABC') fromdual;
select utl_raw.bit_xor('ABC', '') fromdual;
select utl_raw.bit_xor('', 'ABC') fromdual;
select utl_raw.bit_xor('', '') from dual;
select utl_raw.bit_xor(null, '') from dual;
select utl_raw.bit_xor(null, null) fromdual;
select utl_raw.bit_xor('f000', 'EE10') fromdual;
select utl_raw.bit_xor('000', '111') fromdual;
select utl_raw.bit_xor('1111', '111') fromdual;

SELECT utl_raw.bit_complement('0102F3')FROM dual;
SELECTutl_raw.bit_complement('00000000000000000000000000') FROM dual;
SELECTutl_raw.bit_complement('FFFFFFFFFFFFFFFFFFFFFFFFFffffff') FROM dual;
SELECT utl_raw.bit_complement('0246813579')FROM dual;
SELECTutl_raw.bit_complement('ABCDEF13579') FROM dual;
SELECT utl_raw.bit_complement('') FROMdual;
SELECT utl_raw.bit_complement(null) FROMdual;


select utl_raw.substr('1234567810', -4, 3)from dual;
select utl_raw.substr('1234567810', -5, 5)from dual;
select utl_raw.substr('1234567810', -5)from dual;
select utl_raw.substr('1', 0) from dual;
select utl_raw.substr('1', '1') from dual;
select utl_raw.substr('ABCD', '1E0') fromdual;
select utl_raw.substr('ABCD', '1E-1') fromdual;
select utl_raw.substr('ABCD', '0.2') fromdual;

select utl_raw.length(repeat('AB', 32768))from dual;
select utl_raw.length('') from dual;
select utl_raw.length(1E10||'') from dual;
select utl_raw.length(null) from dual;


select utl_raw.reverse('ABC123') from dual;
select utl_raw.reverse('ABCD') from dual;
select utl_raw.reverse('A') from dual;
select utl_raw.reverse(123E3||'') fromdual;

select utl_raw.concat('ABC') from dual;
select utl_raw.concat('ABC', '') from dual;
select utl_raw.concat('ABC', 99E2||'') fromdual;
select utl_raw.concat('', 'ABC') from dual;
select utl_raw.concat('', '') from dual;
select utl_raw.concat('') from dual;
select utl_raw.concat() from dual;
select utl_raw.concat('', null) from dual;
select utl_raw.concat(null, null) fromdual;
select utl_raw.concat('', '') from dual;
select utl_raw.concat(repeat('ABCD', 2000),repeat('ABCD', 2000)) from dual;

select utl_raw.compare('912', '') fromdual;
select utl_raw.compare('912', null) fromdual;
select utl_raw.compare('', null) from dual;
select utl_raw.compare(null, null) from dual;
select utl_raw.compare('912', '91245') fromdual;
select utl_raw.compare('ABC', 'ABCDEFF')from dual;
select utl_raw.compare('ABCD', 'ABCDEFF')from dual;


select utl_raw.COPIES('AB', 10) from dual;
select utl_raw.COPIES('AB123', 10) fromdual;


select utl_raw.cast_to_varchar2('1') fromdual;
select utl_raw.cast_to_varchar2('') fromdual;
select utl_raw.cast_to_varchar2(null) fromdual;
select utl_raw.cast_to_varchar2('6666')from dual;
selectutl_raw.cast_to_varchar2('E4BDA0E5A5BD') from dual;

select utl_raw.CAST_TO_RAW('ff') from dual;
select utl_raw.CAST_TO_RAW(' ') from dual;
select utl_raw.CAST_TO_RAW('') from dual;
select utl_raw.CAST_TO_RAW(null) from dual;
select utl_raw.CAST_TO_RAW(123) from dual;
select utl_raw.CAST_TO_RAW(123E4) fromdual;
select utl_raw.CAST_TO_RAW('嗯嗯ABC123.5') from dual;