我从这个示例修改了以下源代码,以使用NUMBERS
而不是VARCHAR2
.
CREATE OR REPLACE PACKAGE gen_encr
AS
FUNCTION encrypt (p_PlainText NUMBER) RETURN RAW DETERMINISTIC;
FUNCTION decrypt (p_Encrypted RAW) RETURN NUMBER DETERMINISTIC;
END;
/
CREATE OR REPLACE PACKAGE BODY gen_encr
AS
EncryptionType PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256
+ DBMS_CRYPTO.CHAIN_CBC
+ DBMS_CRYPTO.PAD_PKCS5;
EncryptionKey RAW (32) := UTL_RAW.cast_to_raw('ThisTextIsMyEncryptionKeyForThisPackage');
FUNCTION encrypt (p_PlainText NUMBER) RETURN RAW DETERMINISTIC
IS
encrypted_raw RAW (1024);
BEGIN
encrypted_raw := DBMS_CRYPTO.ENCRYPT
( src => UTL_RAW.CAST_FROM_NUMBER (p_PlainText),
typ => EncryptionType,
key => EncryptionKey
);
RETURN encrypted_raw;
END encrypt;
FUNCTION decrypt (p_Encrypted RAW) RETURN NUMBER DETERMINISTIC
IS
decrypt_raw RAW (1024);
BEGIN
decrypt_raw := DBMS_CRYPTO.DECRYPT
( src => p_Encrypted,
typ => EncryptionType,
key => EncryptionKey
);
RETURN (UTL_RAW.CAST_TO_NUMBER (decrypt_raw));
END decrypt;
END;
/
但是,当我运行语句时SELECT sys.gen_encr.encrypt(sal) FROM emp
,出现以下错误。
ORA-06502: PL/SQL: numeric or value error: raw variable length too long
ORA-06512: at "SYS.GEN_ENCR", line 13
一些谷歌搜索提示错误可能是 RAW 数据类型只能接受 2000 字节。
但是,在这种情况下,我不明白为什么会出现错误。任何帮助表示赞赏。