将varchar2强制转换为long、raw、clob并查找hash md5

1sbrub3j  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(538)

有一个带有字段的表 (str1 VARCHAR2(4000 CHAR),str2 VARCHAR2(4000 CHAR)) 有一个带有字段的表b (str1 VARCHAR2(4000 CHAR),str2 VARCHAR2(4000 CHAR),hash_code NUMBER) ```
begin
insert into B(str1,str2,hash_code)
select str1, str2, standart_hash(str1 ||str2,'MD5') as hash_code from A;
commit;
end;

因此,当 `length(str1||str2)` 大于4000(varchar2太小)。
我怎么能把它换成其他类型的呢 `clob` 在这样的环境下? `to_clob(str1 || str2)` 不起作用。
以及 `standart_hash` 不适用于 `clob,long,raw` . 
在解决铸造问题后,我可以用什么来解决这个问题?
v6ylcynt

v6ylcynt1#

varchar2数据类型在pl/sql中的最大长度实际上是32k,标准的\u散列对输入的大小没有限制。另请注意,标准\u hash返回原始数据类型,而不是数字,因为您在示例中定义了hash \u code列。

SQL> desc A
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 STR1                           VARCHAR2(4000)
 STR2                           VARCHAR2(4000)

SQL> desc B
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 STR1                           VARCHAR2(4000)
 STR2                           VARCHAR2(4000)
 HASH_VALUE                     RAW(50)

SQL> select length(str1), length(str2) from A;

LENGTH(STR1) LENGTH(STR2)
------------ ------------
        4000         4000
           3            3

SQL> insert into B (str1, str2, hash_value) select str1, str2, standard_hash(str1||str2,'MD5') as hash_value from A;

2 rows created.

SQL> begin
  2  insert into B (str1, str2, hash_value) select str1, str2, standard_hash(str1||str2,'MD5') as hash_value from A;
  3  commit;
  4  end;
  5  /

PL/SQL procedure successfully completed.

如您所见,我可以毫无问题地运行您的示例。

相关问题