grant execute on dbms_crypto to system; -- 第一个代码块 declare input_string VARCHAR2 (200) := 'Secret Message'; output_string VARCHAR2(2000); encrypted_raw RAW(2000); decrypted_raw RAW(2000); num_key_bytes NUMBER := 256/8; key_bytes_raw RAW(32); encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; begin DBMS_OUTPUT.PUT_LINE(input_string); key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes); encrypted_raw := DBMS_CRYPTO.ENCRYPT(src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_raw); decrypted_raw := DBMS_CRYPTO.DECRYPT(src => encrypted_raw, typ => encryption_type, key => key_bytes_raw); output_string := UTL_I18N.RAW_TO_CHAR(decrypted_raw, 'AL32UTF8'); DBMS_OUTPUT.PUT_LINE(output_string); end; -- 第二个代码块 declare l_src_data varchar2(20); l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) := '0123456789123456'; l_encval raw(2000); cursor secret_cursor is select phonenumber from customer; begin open secret_cursor; loop fetch secret_cursor into l_src_data; exit when secret_cursor%notfound; l_encval := dbms_crypto.encrypt(src => utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8')); dbms_output.put_line(l_encval); end loop; close secret_cursor; end; -- 第三个代码块 declare l_src_data raw(100) := hextoraw('190248129038903853275ijdkvjkad'); l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) := '0123456789123456'; l_decval raw(200); begin l_decval := dbms_crypto.decrypt(src => l_src_data, typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8')); end; -- SQL 查询语句 SELECT Price FROM PRODUCT WHERE ProductID = 5;declare * ERROR at line 18: ORA-06550: line 18, column 1: PLS-00103: Encountered the symbol "DECLARE"报错
时间: 2023-08-24 08:06:19 浏览: 199
存储过程性能检查.docx
这个报错是因为你在最后的 SQL 查询语句前面加了一个 DECLARE 关键字,导致 PL/SQL 解释器无法理解这个语句。请将这个 DECLARE 关键字删除,只保留 SQL 查询语句即可。以下是修正后的代码:
```
grant execute on dbms_crypto to system;
-- 第一个代码块
declare
input_string VARCHAR2 (200) := 'Secret Message';
output_string VARCHAR2(2000);
encrypted_raw RAW(2000);
decrypted_raw RAW(2000);
num_key_bytes NUMBER := 256/8;
key_bytes_raw RAW(32);
encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
begin
DBMS_OUTPUT.PUT_LINE(input_string);
key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes);
encrypted_raw := DBMS_CRYPTO.ENCRYPT(src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_raw);
decrypted_raw := DBMS_CRYPTO.DECRYPT(src => encrypted_raw, typ => encryption_type, key => key_bytes_raw);
output_string := UTL_I18N.RAW_TO_CHAR(decrypted_raw, 'AL32UTF8');
DBMS_OUTPUT.PUT_LINE(output_string);
end;
-- 第二个代码块
declare
l_src_data varchar2(20);
l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
l_key varchar2(20) := '0123456789123456';
l_encval raw(2000);
cursor secret_cursor is select phonenumber from customer;
begin
open secret_cursor;
loop
fetch secret_cursor into l_src_data;
exit when secret_cursor%notfound;
l_encval := dbms_crypto.encrypt(src => utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8'));
dbms_output.put_line(l_encval);
end loop;
close secret_cursor;
end;
-- 第三个代码块
declare
l_src_data raw(100) := hextoraw('190248129038903853275ijdkvjkad');
l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
l_key varchar2(20) := '0123456789123456';
l_decval raw(200);
begin
l_decval := dbms_crypto.decrypt(src => l_src_data, typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8'));
end;
-- SQL 查询语句
SELECT Price FROM PRODUCT WHERE ProductID = 5;
```
这样代码就可以正确执行了。
阅读全文