我在 Apex 页面中有一个 pl/sql 处理代码部分,它使用变量调用数据库链接。
例如:
Cursor crec is select link from db_links;
Begin
l_sql := 'insert into emp values select * from emp_dets@db_link';
For rec in crec
LOOP
l_replace := replace (l_sql,db_link,rec.link)
Execute l_replace into l_sql;
END LOOP;
END;
运行时,出现错误:在替换链接的行中找不到连接描述。
可以访问可用的数据库链接。
从 emp_dets@DEV 选择*;我运行一下就可以访问了。
仍然出现错误。
可能的原因是什么?
这个循环看起来很奇怪......
Execute l_replace into l_sql;
是做什么的?在我的示例中,我将其替换为 EXECUTE IMMEDIATE
。
最有可能的原因是sql错误。检查一下。最好的起点是使用 apex_debug 来检测你的代码。这样你就可以更快地自己调试东西。
对于您的代码:
Cursor crec is select link from db_links;
Begin
l_sql := 'insert into emp values select * from emp_dets@db_link';
apex_debug.info(p_message => q'#my personal debug: before loop#');
For rec in crec
LOOP
l_replace := replace (l_sql,db_link,rec.link);
apex_debug.info(
p_message => q'#my personal debug l_replace: %0#',
p0 => l_replace);
EXECUTE IMMEDIATE l_replace;
END LOOP;
apex_debug.info(p_message => q'#my personal debug: after loop#');
END;
然后打开页面,启用调试,运行进程并调查调试条目以查看记录的内容。