日期:2014-05-17  浏览次数:20826 次

着急,求一个存储过程~只有30了。都给了!在线等!
用游标查一条记录,然后以游标中一条记录的值为条件,在查询。怎么做。begin开始了好象不能再声明游标了,而且存储过程里只能设置游标记录?


create   or   replace   procedure   CREATE_PDH_TEST_DATA   (EndID   integer)is
adevice     device%rowtype;
zdevice     device%rowtype;


trnasSystemId   integer   :=   1000000;

pdhConnectionPortId   integer   :=   1;


transSystemDeviceA   integer;
transSystemDeviceZ   integer;

StartID   integer   :=     1;    


CURSOR   C_Device   IS   select   *   from   device   where   type   =10   and   sub_type   =1001;
      begin
            while   StartID   <=   EndID
      Loop
                        open   C_Device;
                        fetch   C_Device   into   adevice;
                        EXIT   WHEN   C_Device%NOTFOUND;        
                   
                    fetch   C_Device   into   zdevice;
                    EXIT   WHEN   C_Device%NOTFOUND;      
          insert   into   RMS.Trans_System(ID,   NAME,   HIERARCHY,   TOPO_STRUCTURE,   RATE,   RANK,   A_DEVICE_ID,   Z_DEVICE_ID)   Values   (trnasSystemId,   '测试 '||trnasSystemId,     1,     1,     1,   1,   adevice.id,   zdevice.id);
          commit;
          trnasSystemId   :=   trnasSystemId   +   1;
          --这里用游标中的记录为条件查询,不过好象begin开始了就不能再
          --用游标了。而且不知道如何遍历游标啊~~
        CURSOR   A_PORT_BY_140   IS   select   *   from   port   p   where   p.DEVICE_ID   =   adevice.id   and   p.REF_TYPE_ID   =   4   ;
       

        END   Loop
          close   C_Device;
end   CREATE_PDH_TEST_DATA;

------解决方案--------------------
open C_Device;

这句在while循环里面open了无数次,只有最后End loop时关闭了一次
------解决方案--------------------
也就是说:游标依然是在Begin前定义的,但其条件可以通过变量来传递。