Oracle 使用 UTL_RAW.cast_to_raw 插入 RAW

Oracle INSERTING into RAW with UTL_RAW.cast_to_raw

我 运行 进入一些从未实现的代码(见下文)。

CREATE TABLE encryption_values
(
  NAME   VARCHAR2(6),
  VALUE  NVARCHAR2(100)
);
/

insert into encryption_values
select 'key' name,
rawtohex (
rpad ('52AB32;^$!ER94988OPS3W21@@=WTQ32',32,'X')
) value
from dual
union
select 'iv' name,
rawtohex (
rpad ('TY54ABCX12@÷×+==643QREVDG43AAYMN',32,'X')
) value
from dual;

我想将 table 定义从 NVARCHAR2(100) 更改为 RAW(256)。我尝试使用 UTL_RAW.cast_to_raw() 但我 运行 遇到了一些语法错误。有人可以给我提供正确的语法吗?注意我想保留 RPAD 以确保我正在转换 32 个字符字节。

我希望将数据插入到这个 table 定义中。


CREATE TABLE encryption_values
(
  NAME   VARCHAR2(6),
  VALUE  RAW(256)
);
/

您使用了错误的功能,rawtohex。你必须在你的情况下使用包 utl_raw

中的 cast_to_raw

This function converts a VARCHAR2 value represented using some number of data bytes into a RAW value with that number of data bytes. The data itself is not modified in any way, but its datatype is recast to a RAW datatype.

演示

SQL> desc encryption_values
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 NAME                                               VARCHAR2(6)
 VALUE                                              RAW(256)

SQL> insert into encryption_values
  2  select 'key' name,
  3  utl_raw.cast_to_raw (rpad('52AB32;^$!ER94988OPS3W21@@=WTQ32',32,'X')) value
  4  from dual
  5  union
  6  select 'iv' name,
  7  utl_raw.cast_to_raw (rpad('TY54ABCX12@÷×+==643QREVDG43AAYMN',32,'X')) value
  8* from dual
SQL> /

2 rows created.

SQL> select * from encryption_values ;

NAME
------
VALUE
--------------------------------------------------------------------------------
iv
5459353441424358313240EFBFBDEFBFBDEFBFBDEFBFBD2B3D3D3634335152455644473433414159

key
3532414233323B5E2421455239343938384F50533357323140403D5754513332