DECLARE
a number(20):=5;
BEGIN
FOR a in 1..20 LOOP
dbms_output.put_line('value: '|| a);
a:=a+2;
END LOOP;
END;
错误是:
Error report: ORA-06550: line 8, column 5: PLS-00363: expression 'A' cannot be used as an assignment target ORA-06550: line 8, column 5: PL/SQL: Statement ignored 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
我怎样才能做到这一点?
最佳答案
for循环中的a
是for循环索引,是只读的。
注意,for循环中的a
是隐式声明的,与a
部分中的declare
不同。
这在documentation中进行了解释。
如果要在循环内修改变量a
的值,只需为for循环索引指定另一个名称:
DECLARE
a number(20):=5;
BEGIN
-- Note that no declaration of b is necessary
FOR b in 1..20 LOOP
dbms_output.put_line('value: '|| a);
a:=a+2;
END LOOP;
END;
关于sql - 如何循环PL/SQL的:=a+2;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20246556/