【发布时间】:2014-10-26 14:46:22
【问题描述】:
我正在编写脚本,在将行值保存到变量时出错 我正在尝试更新需要从其他相应表中获取的表
DECLARE
cur SYS_REFCURSOR;
dept_row department%rowtype;
employee_row employee%rowtype;
status number :=0;
BEGIN
FOR employee_details IN (select * from employee_details_table)
LOOP
select * into dept_row from department dept where employee_details.dept_id = dept.dept_id;
select * into employee_row from employee emp where emp.dept_id = empoyee_details.dept_id;
IF employee_details.valid <> employee_row.valid THEN
// call SP which uses values from both dept_row & employee_row
END IF;
END LOOP;
COMMIT;
END;
/
当我运行上述 SQL 时,我遇到了错误。 ORA-01722 ORA-06512
我无法弄清楚上面的代码有什么问题。 请帮忙
谢谢
【问题讨论】:
-
您错误地使用了
collection。此外,最好避免使用 for 的循环,并使用批量收集和 forall 语句来最小化 sql 和 plsql 引擎之间的上下文切换的开销。检查我的答案。
标签: database oracle loops plsql cursor