我试图在IF条件中使用Cursor FOR循环并获得错误。 以下是详细信息:
OPEN c_tab_var FOR v_sql;
Loop
fetch c_tab_var into v_cur_inv_var;
exit when c_tab_var%notfound;
For v_cur_bde IN
(
SELECT DISTINCT BDE.col1, BDE.col2
FROM tab BDE
ORDER BY BDE.col1, BDE.col2, BDE.col3....
)
LOOP
If v_cur_bde.col1 = v_cur_inv_var.col1 AND v_cur_bde.col2 = v_cur_inv_var.col2 THEN
(
FOR v_cur_var IN
(
SELECT.....
)
LOOP
-
-
-
)
ELSE
(
-
-
-
)
END IF;
以下是我遇到的错误:
PROCEDURE ABC的编译错误
错误:PLS-00103:遇到以下任何一种情况时遇到符号“FOR”:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql stddev
sum variance execute forall merge time timestamp interval
date <a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternative
行:57 文字:FOR v_cur_var IN
错误:PLS-00103:遇到以下其中一项时遇到符号“)”:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
线:210 文字:))
任何帮助都会受到赞赏!!!!
答案 0 :(得分:0)
我最接近没有语法错误的东西是:
BEGIN OPEN c_tab_var FOR v_sql;
LOOP FETCH c_tab_var INTO v_cur_inv_var;
EXIT WHEN c_tab_var%NOTFOUND; FOR v_cur_bde IN ( SELECT DISTINCT BDE.col1, BDE.col2 FROM tab BDE ORDER BY BDE.col1, BDE.col2, BDE.col3) LOOP IF v_cur_bde.col1 = v_cur_inv_var.col1 AND v_cur_bde.col2 = v_cur_inv_var.col2 THEN FOR v_cur_var IN (SELECT 1 FROM DUAL) --add your select statement for this loop LOOP NULL; --do something END LOOP; ELSE NULL; -- do something else END IF; END LOOP; END LOOP; END;
但如果不了解背景,就无法正确回答这个问题