Oracle 随机数 记录时间 for循环

create or replace procedure Proc_startPunchWork
as

declare
 hh         integer := 7;
  mm         integer;
  ss         integer;
  todayDate  varchar2(20);
  systemDate varchar2(30);
  wendu      varchar(10);
  state      integer := 0;
  startDate  Date;
begin
  for person in (select t.id from t_users t where t.id in(1,2,3,4,5,6,7,8,9,10,12,13,455)) loop
    select t.mmval
      into mm
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select t.mmval
      into ss
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select t.mmval
      into ss
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select s.systime, s.today
      into systemDate, todayDate
      from (select to_char(sysdate, 'yyyy-MM-dd ') || hh || ':' || mm || ':' || ss as systime,
                   to_char(sysdate, 'yyyy-MM-dd ') as today
              from dual) s;
    select p.wendu
      into wendu
      from (SELECT trunc(dbms_random.value(36.1, 36.7), 1) wendu FROM dual) p;
    /*dbms_output.put_line(todayDate);
    dbms_output.put_line(systemDate);*/
    select count(*)
      into state
      from T_PUNCHRECORDS t
     where t.userid = person.id
       and t.today = to_date(todayDate, 'yyyy-MM-dd');
    dbms_output.put_line(state);
    if state = 1 then
      select t.startworktime
        into startDate
        from T_PUNCHRECORDS t
       where t.userid = person.id
         and t.today = to_date(todayDate, 'yyyy-MM-dd');
      if startDate > to_date(todayDate||' 8:0:0', 'yyyy-MM-dd hh:mi:ss') then
        UPDATE T_PUNCHRECORDS a
           SET a.startworktime = to_date(systemDate, 'yyyy-MM-dd hh:mi:ss'),
               a.STARTFLAG     = 1,
               a.inserttime    = to_date(systemDate, 'yyyy-MM-dd hh:mi:ss')
         where a.userid = person.id
           and a.today = to_date(todayDate, 'yyyy-MM-dd');
      end if;
    else
      INSERT into T_PUNCHRECORDS a
        (A.ID,
         a.userid,
         a.today,
         a.startworktime,
         a.STARTFLAG,
        a.MTEMP,
         a.inserttime)
      VALUES
        ((select nvl(max(ID), 0) + 1 from T_PUNCHRECORDS),
         person.id,
         to_date(todayDate, 'yyyy-MM-dd hh:mi:ss'),
         to_date(systemDate, 'yyyy-MM-dd hh:mi:ss'),
         1,
         wendu,
         to_date(systemDate, 'yyyy-MM-dd hh:mi:ss'));
    end if;
    end loop;
  commit;
end;

 

--下午打卡
create or replace procedure Proc_endPunchWork as

  declare
  hh         integer := 17;
  mm         integer;
  ss         integer;
  todayDate  varchar2(20);
  systemDate varchar2(30);
  wendu      varchar(10);
  state      integer := 0;
  startDate  Date;
  endFlag    integer := 0;
begin
  for person in (select t.id from t_users t where t.id in(1,2,3,4,5,6,7,8,9,10,12,13,455)) loop
    select t.mmval
      into mm
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select t.mmval
      into ss
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select t.mmval
      into ss
      from (select trunc(dbms_random.value(0, 60)) as mmval from dual) t;
    select s.systime, s.today
      into systemDate, todayDate
      from (select to_char(sysdate, 'yyyy-MM-dd ') || hh || ':' || mm || ':' || ss as systime,
                   to_char(sysdate, 'yyyy-MM-dd ') as today
              from dual) s;
    select p.wendu
      into wendu
      from (SELECT trunc(dbms_random.value(36.1, 36.7), 1) wendu FROM dual) p;
 
    select count(*)
      into state
      from T_PUNCHRECORDS t
     where t.userid = person.id
       and t.today = to_date(todayDate, 'yyyy-MM-dd');
    dbms_output.put_line(state);
    if state = 1 then
      select t.endworktime, t.endflag
        into startDate, endFlag
        from T_PUNCHRECORDS t
       where t.userid = person.id
         and t.today = to_date(todayDate, 'yyyy-MM-dd');
      if endFlag = 0 then
        UPDATE T_PUNCHRECORDS a
           SET a.endworktime = to_date(systemDate, 'yyyy-MM-dd hh24:mi:ss'),
               a.endflag     = 1,
               a.atemp =wendu
         where a.userid = person.id
           and a.today = to_date(todayDate, 'yyyy-MM-dd');
      end if;
    end if;
  end loop;
  commit;
end;
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值