现在的位置: 首页 > 综合 > 正文

oracle pl_sql 通过游标循环取数字的方法

2013年10月11日 ⁄ 综合 ⁄ 共 943字 ⁄ 字号 评论关闭
declare
  cursor o is
select distinct to_char(report_date,'yyyymmdd') report_date from My_test_DAY_REPORT where report_date >=to_date(20130501,'yyyymmdd') order by 1;
  riqi o%rowtype;
begin
  open o;
   loop fetch o
    into riqi;
  exit when o%notfound;
dbms_output.put_line(riqi.report_date);
  delete from tmp_no_rijie  where run_date=to_date(riqi.report_date, 'yyyymmdd');
  commit;
  insert into tmp_no_rijie
  select t1.org_code      ,
         t1.org_name      ,
         t1.org_type_id   ,
         t1.org_type_name ,
         t1.sup_org_code  ,
         t2.org_name      ,
         t1.usable       ,
         to_date(riqi.report_date, 'yyyymmdd')
    from sys_org t1, (select org_name, org_code from sys_org) t2
   where org_type_id = 18
     and usable = 1
     and t1.sup_org_code = t2.org_code
     and t1.org_code in (130002,
                         150002,
                         150057,
                         150059,
                         150058,
                         140023,
                         140001,
                         110001,
                         170006,
                         170002,
                         180003,
                         140024)
     and t1.org_code not in
         (select org_code
            from My_test_DAY_REPORT
           WHERE report_date = to_date(riqi.report_date, 'yyyymmdd'));
           commit;
end loop;

close o;
end;
/
select run_date as 日期,org_code as 组织,org_name as 组织名,'未做日结' from tmp_no_rijie order by 1;
 
 

oracle pl_sql 通过游标循环取数字的方法

抱歉!评论已关闭.