17,086
社区成员
发帖
与我相关
我的任务
分享
create or replace package body LogOperation2 is
procedure pLog_system_sel
(
plistLog out listlog,
pPageSize in integer,
pPageCurrent in integer,
pRowCount out integer,
pPageCount out integer,
pStartTime in nvarchar2,
pEndTime in nvarchar2,
OrganUnitName in nvarchar2,
OrderNo in nvarchar2
)
as
sqlstr varchar2(1000);
pBegRow integer;
pEndRow integer;
startTime date;
endTime date;
begin
--定义开始和结束行数
pBegRow := (pPageCurrent - 1) * pPageSize + 1;
pEndRow := pPageCurrent * pPageSize;
--日期不为空,把字符串转换成日期
if(length(pStartTime) > 0) and (length(pEndTime) > 0) then
startTime := to_date(concat(pStartTime,' 00:00:01'),'yyyy-mm-dd hh24:mi:ss');
endTime := to_date(concat(pEndTime,' 23:59:59'),'yyyy-mm-dd hh24:mi:ss');
end if;
--开始确认行数
sqlstr := 'select count(1) into :pRowCount from Log_system a where 1 = 1 ';
--时间
if(length(pStartTime) > 0) and (length(pEndTime) > 0) then
sqlstr := sqlstr || ' and a.ExamineDate between '|| startTime ||' and '|| endTime;
end if;
--名称
if length(OrganUnitName) > 0 then
sqlstr := sqlstr || ' and b.UnitName like ''%' ||OrganUnitName|| '%''';
end if;
--单号
if length(OrderNo) > 0 then
sqlstr := sqlstr ||' and c.OrderNo like ''%'||OrderNo || '%''';
end if;
execute immediate sqlstr into pRowCount;
--计算页数
if pRowCount = 0 then
pPageCount := 0;
else
pPageCount := ceil(pRowCount * 1.0 / pPageSize) ;
end if;
--结果集
sqlstr := 'select * from (';
sqlstr := sqlstr || 'select rownum as rn,a.Examine_ID,a.User_ID,Status_ID,ExamineRemark,ExamineDate,';
sqlstr := sqlstr || ' OrderNo from Log_system where 1=1';
--时间
if(length(pStartTime) > 0) and (length(pEndTime) > 0) then
sqlstr := sqlstr || ' and ExamineDate between '|| startTime ||' and '|| endTime;
end if;
--单位名称
if length(OrganUnitName) > 0 then
sqlstr := sqlstr || ' and OrganUnitName like ''%' ||OrganUnitName|| '%''';
end if;
--订单号
if length(OrderNo) > 0 then
sqlstr := sqlstr ||' and OrderNo like ''%'||OrderNo || '%''';
end if;
sqlstr := sqlstr || ' )where rn between :pBegRow and :pEndRow';
pMsg := sqlstr;
open plistLog for sqlstr using pBegRow,pEndRow;
end;
end;
if 条件1 then
if 条件2 then
open plistLog for sqlstr using 条件1,条件2;
else
open plistLog for sqlstr using 条件1;
end if;
else
if 条件2 then
open plistLog for sqlstr using 条件2;
else
open plistLog for sqlstr;
end if;
end if;