日期:2014-05-16  浏览次数:21019 次

把游标中的数据插入到表A中
本帖最后由 lihuinihao6315 于 2013-04-09 17:03:53 编辑

declare
    P_Where VARCHAR2(10) :='1=1'; ---------查询条件
    cur_out  sys_refcursor;  --记录集游标

begin
    P_Excute(P_Where,cur_out);--执行存储过程 得到游标记录
     cur_out 。。。 ---这里将游标中的记录插入到表A中。 表A比游标多1列是日期,默认当前日期。 其他列都一样。
游标,Oracle SQL

------解决方案--------------------

declare
    P_Where VARCHAR2(10) :='1=1'; ---------查询条件
    cur_out  sys_refcursor;  --记录集游标
    cursor atype is select 除了默认日期那列都要 from A;
    p_row atype%rowtype;
begin
    P_Excute(P_Where,cur_out);--执行存储过程 得到游标记录
    loop
        fetch cur_out into p_row;
        exit when cur_out%notfound;
        insert into A(默认日期那列,其余列...) values(sysdate,p_row.col1,p_row.col2......);
    end loop;
    close cur_out;
    commit;
end;