0
 declare  

   cursor c1 is select ISETID AS ID1 , ISETID1 as ID2 From (select ISetID, ItemsID from FI where ISetID in (Select ISetId from FI group by ISetID having count(ItemsID)=1))  natural join ( select ISetID as IsetID1,ItemsID from FI where ISetID in (Select ISetId from FI group by ISetID  having count(ItemsID)=3));

 v_sf_l  number ;   
 v_sf_b   number;   
 v_confi  number;   
 v_name_l  varchar(200);  
 v_name_b  varchar(200);  

 begin

 for I in c1 loop   
     select distinct sf into v_sf_l from FI where IsetID=I.id1;  
     select distinct sf into v_sf_b from FI where IsetID=I.id2;  
     v_confi:=v_sf_b/v_sf_l;  
     select distinct wm_concat(ItemsName) into v_name_l from FI,items where IsetID=I.id1 and FI.ItemsID =Items.ItemsID;        
     select distinct replace(wm_concat(ItemsName),v_name_l,'')  into v_name_b from FI,items where IsetID=I.id2 and FI.ItemsID =Items.ItemsID;         
     v_name_b:=trim(replace(v_name_b,',',' '));  

     execute immediate('Insert into apr(name1,name2,conf)  values ('||v_name_l||','||v_name_b||','||v_confi||')');

     dbms_output.put_line(v_name_l||','||v_name_b||','||v_confi);

     end loop;
end;
   /

每当我执行此脚本时,当我使用 dbms_output.put_line 时,执行立即插入时会出现逗号丢失错误!!!!

4

1 回答 1

0

在我看来,您的立即执行好像缺少字符串周围的一些引号。希望下面的代码说明了如何插入它们。

declare  


v_confi  number(6) := 10 ;   
v_name_l  varchar(200) := 'ads';  
v_name_b  varchar(200) := 'edf';  
v_text varchar2(1000);

begin

v_text := 'Insert into apr(name1,name2,conf)  values   ('''||v_name_l||''','''||v_name_b||''','||TO_CHAR(v_confi)||')';

 execute immediate(v_text);


end;
于 2012-11-27T21:23:12.320 回答