oracle游标 抓狂问题
declare
     v_pn number := 2462;
     cursor c_cursor_relcon is  
	   		select sn, relatives_id, pn, customer_name from info_relatives_concern where pn = v_pn;
begin          
     if not c_cursor_relcon%isopen then                           
		 open c_cursor_relcon;
     end if;                                      
	 for c_rec in c_cursor_relcon loop  	  
	 	 dbms_output.put_line(c_rec.sn || ',' || c_rec.relatives_id || ', ' || c_rec.pn || ', ' || c_rec.customer_name);	  
	 end loop;
     close c_cursor_relcon;
end;
这是我的代码,执行时总是提示 PL/SQL:游标已打开,但我运行close c_cursor_relcon又说无效的sql语句
------解决方案--------------------
for 循环的特性, 游标不需要显示打开和关闭,甚至不需要声明也可以。
童鞋,基础问题。。。
SQL code
--你这个完全可以写成
DECLARE
  V_PN NUMBER := 2462;
BEGIN
  FOR C_REC IN (SELECT SN, RELATIVES_ID, PN, CUSTOMER_NAME
                  FROM INFO_RELATIVES_CONCERN
                 WHERE PN = V_PN) LOOP
    DBMS_OUTPUT.PUT_LINE(C_REC.SN || ',' || C_REC.RELATIVES_ID || ', ' ||
                         C_REC.PN || ', ' || C_REC.CUSTOMER_NAME);
  END LOOP;
END;
------解决方案--------------------
for循环会帮你自动开启游标,循环结束会帮你自动关闭游标,所以不用手动关闭