首页 > 数据库 > Oracle > 正文

oracle日期类型数据查询解决例子

2024-08-29 13:31:37
字体:
来源:转载
供稿:网友

create table worklog_a(
   man_bar            char(8) not null,
   man_name           varchar2(22) not null,
   man_dep            varchar2(40) not null,
   log_time           date not null
   status             varchar2(40)
);
create unique index worklog_a_index 
on workman(man_bar,man_name);
comment on table worklog_a is
'登到日记表';

sql:='select man_bar as "考勤条码",man_name as "姓名",log_time as "登记时间",status as "状态",man_dep as "所属部门" ';
sql:=sql+' from worklog_a where man_bar='+''''+s11+''''
          +' and (to_char(trunc(log_time,'+'''dd'''+')'+','+'''yyyy-mm-dd'''+') between '
          + ''''+getdatestr(dat1.date)+''''+' and '+''''+getdatestr(dat2.date)+'''' ;
sql:=sql+') order by log_time desc';
runsql(ado_pall,sql,0);

function tfrmain.getdatestr(dat: tdatetime): string;
var
  year, month, day:word;
begin
  decodedate(dat,year,month,day);
  if(month>=10) then
        result:= inttostr(year) + '-'+inttostr(month)
  else
        result:= inttostr(year)+ '-' +'0'+ inttostr(month) ;
  if(day>=10) then
      result:=result+ '-'+inttostr(day)
  else
     result:=result+ '-'+'0'+inttostr(day);
end;

 

              sql1:='insert into worklog_a values(';
              sql1:=sql1+''''+s1+''''+','+''''+s2+''''+','+''''+s3+''''+',';
              sql1:=sql1+'sysdate'+','+''''+kk+''''+')';
              runsql(ado_kqlog,sql1,1);
              statusbar1.simpletext:='今天总计:'+inttostr(ado_tm.recordcount+1)+'  考勤' ;

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表