我正在编写一个SQL过程来执行以下任务。
表A可以包含任意数量的COL1、COL2和COL3组合。
这里我正在读取表A中的所有数据,但我不想每次都对表B进行搜索查询,以查找表B中的键。但我喜欢将表B的数据存储/获取在某个地方(map等),然后在那里搜索并插入表C。
简而言之,我希望缓存表B数据并执行搜索和获取数据。
发布于 2014-08-12 09:49:28
我们经常使用数组来缓存数据以查找值,例如我们有一个t_sites表,我们想要缓存整个数据集,主键是varchar2(10),所以我们创建了一个由varchar2(10)索引的数组.下面是代码的一个示例:
declare
-- type and array to hold all the data from the query
type sites_rec_t is record (
addr_id t_sites.addr_id%type,
code t_sites.code%type,
description t_sites.description%type,
pm_telephone t_sites.pm_telephone%type
);
-- array for the lookups
type sites_t is table of sites_rec_t index by varchar2(10);
a_sites sites_t;
v_site_arr_key varchar2(10);
begin
-- populate the arrays
for r in ( select addr_id, code, description, pm_telephone from t_sites ) loop
a_sites(r.code).addr_id := r.addr_id;
a_sites(r.code).code := r.code;
a_sites(r.code).description := r.description;
a_sites(r.code).pm_telephone := r.pm_telephone;
end loop;
-- example of how to loop through the varchar indexed array as you cant do for i in 1 .. array.count loop
v_site_arr_key := a_sites.first;
while v_site_arr_key is not null loop
dbms_output.put_line(v_site_arr_key || '=' || a_sites(v_site_arr_key).description || ', ' || a_sites(v_site_arr_key).addr_id);
v_site_arr_key := a_sites.next(v_site_arr_key);
end loop;
end;https://stackoverflow.com/questions/25259693
复制相似问题