【发布时间】:2012-11-09 17:49:26
【问题描述】:
我的雇主使用的应用程序将有关业务案例的元数据存储在一个主表和大约 40 个详细表中。
目前,我维护了一个包,它从这些表中读取数据并为每个主记录生成一个带有 HTML 输出的文件。
我的包裹体包含以下内容:
type output_text_type is table of varchar(32768);
function fA(mri in master_record_identifier_type)
return output_text_type
is
cursor cA(if1 master_record_identifier_type.if1%type, ...)
is
select tA.f1, tA.f2, ...
from tA
where tA.if1 = if1
...;
begin -- fA
...
for r in cA(mri.if1, mri.if2, ...) loop
<generate HTML using r.f1, r.rf2, mri.if1...>
end loop;
end fA;
... some 40 more function with the same structure ...
顺便说一句,大多数游标返回的记录少于 100 条(通常是 0 或 1 条),因此 fetch ... bulk collect ... 不会带来性能提升。
现在我们计划与其他组织交换业务案例的元数据(当然还有文档本身)。为此,我们必须生成具有 - 实质上 - 相同内容的 xml 数据结构。
为了满足这个要求,我计划将我当前的包(受模型-视图-控制器模式的影响)拆分为一个包 pkg_cursors、一个 pkg_html 和一个(尚未编写的)pkg_xml。
唉,我发现只有一个可行的解决方案,定义如下记录:
create or replace package pkg_cursors
as
type rA is record(
if1 tA.if1%type,
f1 tA.f1%type,
f2 tA.f2%type,
... a dozen more fields ...
);
cursor ca(master_record_identifier_type.if1%type, ...)
return rA;
...
这很不幸,因为直到现在才向表中添加列 导致更新游标的选择子句并将新列添加到游标循环中。从现在开始,我要考虑第三个地方:记录定义。
我还在包规范中尝试了游标:
create package pkg_cursors
as
cursor cA(...) is
select <select-list>
from ... where ...
return cA%rowtype;
但我得到了编译错误。
因此,我的问题是:有没有办法避免游标返回参数的记录定义?
你认为有没有更好的拆分包的方法?
(请原谅我的语言错误和这个问题的长度。我对英语的掌握是否更扎实,这个问题可能会更短。)
【问题讨论】:
-
你考虑过动态html吗? dbms_sql 可以做到这一点(参见 dbms_sql.describe_columns)
标签: oracle plsql cursor record rowtype