SQL> CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS 2 C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256'; 3 BEGIN 4 UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT( 5 UTL_I18N.STRING_TO_RAW(TO_CHAR(PRICE), 'AL32UTF8'), 6 DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5, 7 UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'), 8 DBMS_CRYPTO.CHAIN_IV 9 ) WHERE PRICE IS NOT NULL; 10 END; 11 / Warning: Procedure created with compilation errors. SQL> SQL> SHOW ERRORS; Errors for PROCEDURE ENCRYPT_PRICE: LINE/COL ERROR -------- ----------------------------------------------------------------- 4/3 PL/SQL: SQL Statement ignored 8/5 PL/SQL: ORA-00904: "DBMS_CRYPTO"."CHAIN_IV": invalid identifier 8/17 PLS-00302: component 'CHAIN_IV' must be declared
时间: 2023-08-15 19:13:47 浏览: 204
根据错误信息,可以看出问题出在 `DBMS_CRYPTO.CHAIN_IV` 上,因为该标识符无效。实际上,DBMS_CRYPTO 包中没有 `CHAIN_IV` 这个组件,所以需要将其替换为 `NULL`。
修改后的代码如下:
```
CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS
C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256';
BEGIN
UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT(
UTL_I18N.STRING_TO_RAW(TO_CHAR(PRICE), 'AL32UTF8'),
DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'),
NULL
) WHERE PRICE IS NOT NULL;
END;
/
相关问题
SQL> CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS 2 C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256'; 3 BEGIN 4 UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW(TO_CHAR(PRICE), 'AL32UTF8'), 5 DBMS_CRYPTO.AES256_CBC, 6 UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'), 7 DBMS_CRYPTO.CHAIN_IV) WHERE PRICE IS NOT NULL; 8 END; 9 / Warning: Procedure created with compilation errors.
这个程序创建时出现了编译错误,可能是语法错误或其他问题导致的。你可以使用以下命令查询编译错误:
```
SHOW ERRORS;
```
这将显示最近一次编译错误的详细信息,包括错误行数、错误类型和错误消息。
在这种情况下,可能是因为 `DBMS_CRYPTO.AES256_CBC` 不被识别为有效的加密类型。你可以使用 `DBMS_CRYPTO.ENCRYPT_AES256` 替换 `DBMS_CRYPTO.AES256_CBC`,因为后者是前者的一部分。修改后的代码如下:
```
CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS
C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256';
BEGIN
UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT(
UTL_I18N.STRING_TO_RAW(TO_CHAR(PRICE), 'AL32UTF8'),
DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'),
DBMS_CRYPTO.CHAIN_IV
) WHERE PRICE IS NOT NULL;
END;
/
4/3 PL/SQL: SQL Statement ignored 4/42 PL/SQL: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY SQL> CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS 2 C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256'; 3 BEGIN 4 UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT( 5 UTL_I18N.STRING_TO_RAW(CAST(PRICE AS RAW), 'AL32UTF8'), 6 DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5, 7 UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'), 8 NULL 9 ) WHERE PRICE IS NOT NULL; 10 END; 11 / Warning: Procedure created with compilation errors. SQL> show errors; Errors for PROCEDURE ENCRYPT_PRICE: LINE/COL ERROR -------- ----------------------------------------------------------------- 4/3 PL/SQL: SQL Statement ignored 5/45 PL/SQL: ORA-00906: missing left parenthesis
根据错误信息,可以看出问题出在 `UPDATE` 语句中的 `DBMS_CRYPTO.ENCRYPT` 函数上,因为缺少左括号。这可能是因为 `DBMS_CRYPTO.ENCRYPT_AES256`、`DBMS_CRYPTO.CHAIN_CBC` 和 `DBMS_CRYPTO.PAD_PKCS5` 这三个常量之间应该使用竖线 `|` 进行位运算符的 OR 运算,而不是加号 `+`。
修改后的代码如下:
```
CREATE OR REPLACE PROCEDURE ENCRYPT_PRICE AS
C_KEY VARCHAR2(32) := 'MY_SECRET_KEY_FOR_AES256';
BEGIN
UPDATE PRODUCT SET PRICE = DBMS_CRYPTO.ENCRYPT(
UTL_I18N.STRING_TO_RAW(CAST(PRICE AS RAW), 'AL32UTF8'),
DBMS_CRYPTO.ENCRYPT_AES256 | DBMS_CRYPTO.CHAIN_CBC | DBMS_CRYPTO.PAD_PKCS5,
UTL_I18N.STRING_TO_RAW(C_KEY, 'AL32UTF8'),
NULL
) WHERE PRICE IS NOT NULL;
END;
/
阅读全文