欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

oracle 存储过程2个

程序员文章站 2022-04-04 21:55:32
...

实例1:创建1年的日期,并标识是否是周六日

create or replace procedure pro_2 is
i number;
first_day_ date DEFAULT to_date('2015-01-01','yyyy-MM-dd');
begin
i:=1; 
while i<365 loop
  IF TO_CHAR(first_day_,'D')=7 OR  TO_CHAR(first_day_,'D')=1
  THEN 
    INSERT INTO datesetting(ID,ISWORK,WORKTIME) VALUES(i,0,to_char(first_day_,'yyyy-MM-dd'));
  ELSE  
    INSERT INTO datesetting(ID,ISWORK,WORKTIME) VALUES(i,1,to_char(first_day_,'yyyy-MM-dd'));  
  END IF;   
  i:=i+1;
  first_day_:=first_day_+1;  
end loop;
end;

 

实例2:循环一张表记录

create or replace procedure proc1(p1 varchar2,p2 varchar2)
as    
cursor c_postype is select iswork, worktime from datesetting; 
iswork varchar2(20);  
worktime varchar2(20);  
r1 varchar2(20);  
begin     
  open c_postype;   
       loop   
         fetch c_postype into iswork,worktime;   
         exit when c_postype%notfound; 
         dbms_output.put_line('iswork:'||iswork || 'worktime:'||worktime);    
       end loop;     
  close c_postype;   
end;

 

 

 

相关标签: oracle 存储过程