FOR i IN 1..10 LOOP * ERROR at line 2: ORA-06550: line 2, column 5: PLS-00103: Encountered the symbol "FOR" when expecting one of the following: := . ( @ % ; The symbol "(" was substituted for "FOR" to continue. ORA-06550: line 2, column 20: PLS-00103: Encountered the symbol "LOOP" when expecting one of the following: , * & - + / at mod remainder rem when while => <an exponent (**)> by index sequence || multiset
时间: 2024-01-08 18:02:46 浏览: 33
这是一个 PL/SQL 代码块,但是它存在语法错误。可能是因为你没有定义变量 i。你需要在代码块前声明变量 i,例如:
DECLARE
i NUMBER;
BEGIN
FOR i IN 1..10 LOOP
-- Your code here
END LOOP;
END;
请注意,你需要将“Your code here”替换为实际的代码。
相关问题
BEGIN FOR i IN 1..10 LOOP INSERT INTO SHIFT (ShiftID, StartTime, EndTime, StoreID, EmployeeID) VALUES (i, SYSDATE - DBMS_RANDOM.VALUE(1, 7), SYSDATE - DBMS_RANDOM.VALUE(0, 6), i, i); END LOOP; COMMIT; END; FOR i IN 1..10 LOOP * ERROR at line 2: ORA-06550: line 2, column 5: PLS-00103: Encountered the symbol "FOR" when expecting one of the following: := . ( @ % ; The symbol "(" was substituted for "FOR" to continue. ORA-06550: line 2, column 20: PLS-00103: Encountered the symbol "LOOP" when expecting one of the following: , * & - + / at mod remainder rem when while => <an exponent (**)> by index sequence || multiset
这段代码有两个问题:
1. 缺少一个语句块的结尾。你需要在第一段代码的最后加上 `END;` 来结束整个语句块。
2. 你不能在 PL/SQL 块外使用 `FOR` 循环。你需要将两个 `FOR` 循环放在一个 PL/SQL 块内,像这样:
```
BEGIN
FOR i IN 1..10 LOOP
INSERT INTO SHIFT (ShiftID, StartTime, EndTime, StoreID, EmployeeID)
VALUES (i, SYSDATE - DBMS_RANDOM.VALUE(1, 7), SYSDATE - DBMS_RANDOM.VALUE(0, 6), i, i);
END LOOP;
FOR i IN 1..10 LOOP
-- do something else
END LOOP;
COMMIT;
END;
```
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"报错
这个报错是因为你在最后的 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;
```
这样代码就可以正确执行了。
阅读全文