在FOR LOOP中构建数字表

时间:2015-09-22 14:57:33

标签: oracle plsql procedure

我有以下程序,我需要从另一个程序调用。

PROCEDURE get_list_ntds_for_given_port(
  pis_olt_name       IN common.types.string
, pis_chasis_lt_port IN common.types.string
, pona_ntd_ids       OUT common_api.ntabtype
)
IS
  lsa_object_name       common_api.vtabtype;
  lsa_link_type         common_api.vtabtype;
  lsa_link_status       common_api.vtabtype;
  lna_link_object_id    common_api.ntabtype;
  lsa_link_object_name  common_api.vtabtype;
  lsa_link_object_class common_api.vtabtype;
  ln_pon_port_id        NUMBER;
  lna_child_pon_result  FLS_NUMBER_TABLE;
  lona_ntd_ids          common_api.ntabtype;
  ls_pon_port_map       common.types.string;
BEGIN
  ls_pon_port_map := pis_olt_name || '/' || pis_chasis_lt_port;
  ln_pon_port_id := nwmdl.alu_pon_port.find(
      pis_full_pon_port_name => ls_pon_port_map
    );
  lna_child_pon_result:= rm.sri_object_utils.get_child_objects(
      pis_proc_name => lc_proc_name
    , pin_parent_id => ln_pon_port_id
    );
    pona_ntd_ids := common_api.ntabtype();
  FOR i IN 1..lna_child_pon_result.COUNT
  LOOP
    rm.ims_objects_api.get_peer_links (
        pin_object_id          => lna_child_pon_result(i)
      , pis_geographical_only  => 'N'
      , pona_object_id         => lona_ntd_ids
      , posa_object_name       => lsa_object_name
      , posa_link_type         => lsa_link_type
      , posa_link_status       => lsa_link_status
      , pona_link_object_id    => lna_link_object_id
      , posa_link_object_name  => lsa_link_object_name
      , posa_link_object_class => lsa_link_object_class
      ); 
    pona_ntd_ids.EXTEND(lona_ntd_ids.COUNT);
    FOR i IN 1..lona_ntd_ids.COUNT 
    LOOP 
      pona_ntd_ids(i) := lona_ntd_ids(i);
    END LOOP;  
  END LOOP;
END get_list_ntds_for_given_port;

我用这个pl-sql块模拟外部调用:

SET SERVEROUTPUT ON;
DECLARE
lona_ntd_ids common_api.ntabtype;
BEGIN
svcmgr_lni.design_and_assign.get_list_ntds_for_given_port( pis_olt_name        =>  'SWOLT0000003DV'
                              ,pis_chasis_lt_port =>  '1-1/LT1/1'
                              ,pona_ntd_ids       => lona_ntd_ids
                             );
     FOR i IN 1..lona_ntd_ids.COUNT 
      LOOP                       
      DBMS_OUTPUT.PUT_LINE(lona_ntd_ids(i)); 
      END LOOP; 
 END;

问题是我在输出中没有得到任何结果。 我的猜测是,我rm.ims_objects_api.get_peer_links API将为lna_child_pon_result(i)找到的每个rm.sri_object_utils.get_child_objects调用,并且会在每个输出parm中更准确地放入API的OUT参数中的数字表(ID) )或varchar。 我想要实现的是构建主PROCEDURE(get_list_ntds_for_given_port)的数字表并将其设置为输出参数,以便在主过程之外使用该数字表。 请留下您解决此问题的任何想法。

2 个答案:

答案 0 :(得分:1)

试试这个:

移动" pona_ntd_ids:= common_api.ntabtype();"循环之外:

pona_ntd_ids := common_api.ntabtype();
FOR i IN 1..lna_child_pon_result.COUNT

更改

pona_ntd_ids(i) := lona_ntd_ids(i);

pona_ntd_ids(pona_ntd_ids.COUNT+1) := lona_ntd_ids(i); 

因为在原始代码中,你为每个循环初始化pona_ntd_ids,如果最后一次外部迭代产生lona_ntd_ids.COUNT = 0,你将最终没有任何内容。

答案 1 :(得分:1)

你可以进行Lilte修改并批量收集整个对象,然后将其作为OUT参数。是的,这将是程序的开销,因为使用了正则表达式,但它足以满足您的查询。

FOR i IN 1..lona_ntd_ids.COUNT 
    LOOP 
    lv_eg_string := lona_ntd_ids(i)||','||lv_eg_string;
--      pona_ntd_ids(i) := lona_ntd_ids(i);
    END LOOP; 
    lv_eg_string:=substr(lv_eg_string,1,length(lv_eg_string)-1);
    SELECT regexp_substr(lv_eg_string,'[^,]+', 1, level) BULK COLLECT
    INTO pona_ntd_ids
    FROM dual
   CONNECT BY regexp_substr(lv_eg_string, '[^,]+', 1, level);