我想对大数据进行分页。并在每次单击页面时获得100条记录,并且还希望使用Oracle数据库返回“页码,总计记录”。这里的问题是我对Oracle完全不了解。但是我已经在SQL Server中进行了查询。但是客户端需要在Oracle中执行该查询。在SQL Server中,我通过选择到临时表中,然后根据开始和结束参数获取行来计算了分页部分。如果我们需要每页发送100条记录作为响应。我想将下面的SQL Server查询转换为oracle查询。请有人帮忙。
SQL Server查询:
ALTER PROCEDURE [dbo].[abccccc]
@PageNumber varchar(max)=null,
@dtfrom varchar(100) = '',
@dtto varchar(100) = '',
@Search varchar(max)=null
AS
DECLARE @RowsPerPage int = 10
declare @start int=0
declare @end int=0
declare @NumOfRecords int=0
IF @PageNumber IS NULL OR @PageNumber = ''
BEGIN
SET @PageNumber = 1 --by default pageno will be 1
END
set @start = ((@PageNumber - 1) * @RowsPerPage) + 1 --calculating start page
set @end = (@RowsPerPage * (@PageNumber)) --calculating end page
print @start
print @end
BEGIN
--putting data in temp table
select ROW_NUMBER() over (order by ProposerId desc) as SRNO,* into #tmp1 from(
select * from [dbo].[TTB_ProposerDetails] where Active = 1) as data where ((convert(date,CreatedOn,103) <= convert(date,@dtto,103) and
convert(date,CreatedOn,103) >= convert(date,@dtfrom,103) OR IsNull(@dtfrom,'') = '' or IsNull(@dtto ,'') = '')) and
(FirstName like '%' + @Search + '%' or isnull(@Search,'')='' or AccountNo like '%' + @Search + '%' or isnull(@Search,'')=''or
LastName like '%' + @Search + '%' or isnull(@Search,'')='')
set @NumOfRecords=(select count(*) from #tmp1)
select * from #tmp1 where SRNO between @start and @end --fetch from temp tbl
drop table #tmp1
select 'Success' as msg,1 as n,@NumOfRecords as ipara1,(@NumOfRecords/@RowsPerPage) ipara2, @PageNumber as ipara3
END
END
CREATE PROC dbo.Sp_SearchData
(
@PageIndex INT = 1, ---Here We set the Default value to Page No.(i.e.PageIndex)
@PageSize INT = 15, -- and PageSize ie. How many Records do want?
@Mode INT = NULL,
@Name VARCHAR(50) = NULL,
@Address VARCHAR(50) = NULL
)
AS
BEGIN
IF(@Mode=1)
BEGIN
SELECT ROW_NUMBER()OVER
(
ORDER BY ID DESC ---Select Your Column That you want Order wise data
)
AS
RowNumber,
ID,
NAME,ADDRESS ---Put All Your Column Name
INTO #Results ---Here We Dumping the Data In temp Table
FROM TableName
WHERE NAME LIKE ISNULL('%'+(@Name)+'%','')
AND ADDRESS LIKE ISNULL('%'+(@Address)+'%','')
ORDER BY ID
SELECT * FROM #Results --Here you will Get All your Pagination
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
SELECT COUNT(*) AS TotalNumberOfRecords FROM #Results ---Here you will Get Total No. of Records
DROP TABLE #Results
END
END
用于测试存储过程的脚本:-
EXEC dbo.Sp_SearchData
@PageIndex = '2', ---Here i'm Getting All the Records PageNo.--2 data
@PageSize ='15', ---Increase the No. of Records that you want at single time here i'm set 15 ...you can set 100 or more
@Mode='1',
@Name='',
@Address=''
注:-阅读所有注释...开发了自己的逻辑...您将获得输出.....
编辑后:-
begin
declare
PageIndex number;
PageSize number;
Name varchar2(50);
Address varchar2(50);
begin
null;
end;
PageIndex := 1;
PageSize := 15;
Name := '';
Address := '';
create table #Results
as
select
row_number() over (order by ID desc) RowNumber,
ID,
NAME,
ADDRESS ADDRESS
from TableName
where (
NAME like nvl((('%' + @Name) + '%'), '')
and ADDRESS like nvl((('%' + @Address) + '%'), '')
)
order by ID;
select *
from #Results
where RowNumber between (((@PageIndex - 1) * @PageSize) + 1) and (((((@PageIndex - 1) * @PageSize) + 1) + @PageSize) - 1);
select count(*) TotalNumberOfRecords
from #Results;
Drop table #Results Purge;
end;
我已将以上查询转换为Oracle 11g
使用此网站:-https://www.jooq.org/translate/
注意:-我不确定这行Drop table #Results Purge;尝试找出如何在oracle 11 g中删除临时表的方法。...我不确定。...