ÍòÄܵķÖÒ³sql(ת)
CREATE proc page
@RecordCount int output,
@QueryStr nvarchar(100)='table1',--±íÃû¡¢ÊÓͼÃû¡¢²éѯÓï¾ä
@PageSize int=20, --ÿҳµÄ´óС(ÐÐÊý)
@PageCurrent int=2, --ÒªÏÔʾµÄÒ³ ´Ó0¿ªÊ¼
@FdShow nvarchar (1000)='*', --ÒªÏÔʾµÄ×Ö¶ÎÁбí
@IdentityStr nvarchar (100)='id', --Ö÷¼ü
@WhereStr nvarchar (200)='1=1',
@FdOrder nvarchar(100)='desc' --ÅÅÐò Ö»ÄÜÈ¡desc»òÕßasc
as
declare
@sql nvarchar(2000)
set @sql = ''
if @WhereStr = ''
set @WhereStr = '1=1'
if @PageCurrent = 0 begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' ' + @FdOrder
end
else begin
if upper(@FdOrder) = 'DESC' begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' and ' + @IdentityStr + '< ( select min(' + @IdentityStr + ') from (select top ' + cast(@PageSize*@PageCurrent as nvarchar(10)) + ' ' + @IdentityStr + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' desc) as t) order by ' + @IdentityStr + ' desc'
end
else begin
set @sql = 'select top ' + cast(@PageSize as nvarchar(3)) + ' ' + @FdShow + ' from ' + @QueryStr + ' where ' + @WhereStr + ' and ' + @IdentityStr + '> ( select max(' + @IdentityStr + ') from (select top ' + cast(@PageSize*@PageCurrent as nvarchar(10)) + ' ' + @IdentityStr + ' from ' + @QueryStr + ' where ' + @WhereStr + ' order by ' + @IdentityStr + ' asc) as t) order by ' + @IdentityStr + ' asc'
end
end
--print @sql
execute(@sql)
if(@RecordCount is null or @RecordCount<=0)begin
declare @tsql nvarchar(200)
set @tsql=N'select @RecordCount = count(*) from ' + @QueryStr + ' where ' + @WhereStr
exec sp_executesql @tsql,N'@RecordCount int output',@RecordCount output
select @Recordcount
end
GO
Ïà¹ØÎĵµ£º
Ö÷¼ü:
Äܹ»Î¨Ò»±íʾÊý¾Ý±íÖеÄÿ¸ö¼Ç¼µÄ¡¾×ֶΡ¿»òÕß¡¾×ֶΡ¿µÄ×éºÏ¾Í³ÆÎªÖ÷Âë(Ö÷¼ü)¡£ Ò»¸öÖ÷¼üÊÇΨһʶ±ðÒ»¸ö±íµÄÿһ¼Ç¼£¬µ«ÕâÖ»ÊÇÆä×÷ÓõÄÒ»²¿·Ö£¬Ö÷¼üµÄÖ÷Òª×÷ÓÃÊǽ«¼Ç¼ºÍ´æ·ÅÔÚÆäËû±íÖеÄÊý¾Ý½øÐйØÁª¡£ÔÚÕâÒ»µãÉÏ£¬Ö÷¼üÊDz»Í¬±íÖи÷¼Ç¼֮¼äµÄ¼òµ¥Ö¸Õë¡£Ö÷¼üÔ¼Êø¾ÍÊÇÈ·¶¨±íÖеÄÿһÌõ¼Ç¼¡£Ö÷¼ü²»ÄÜÊÇ¿ÕÖµ¡£Î¨Ò ......
×î½ü¿´µ½ºÜ¶àÈ˵ÄÍøÕ¾¶¼±»×¢Èëjs,±»iframeÖ®ÀàµÄ¡£·Ç³£¶à¡£
±¾ÈËÔø½ÓÊÖ¹ýÒ»¸ö±È½Ï´óµÄÍøÕ¾£¬±»È˼ÒÈëÇÖÁË£¬ÒªÎÒÊÕʰ²Ð¾Ö¡£¡£
1.Ê×ÏÈÎÒ»á¼ì²éһϷþÎñÆ÷ÅäÖã¬ÖØÐÂÅäÖÃÒ»´Î·þÎñÆ÷°²È«£¬¿ÉÒԲο¼
http://hi.baidu.com/zzxap/blog/item/18180000ff921516738b6564.html
2.Æä´Î£¬ÓÃÂó¿§·È×Ô¶¨Òå²ßÂÔ£¬¼´Ê¹ÍøÕ¾³ÌÐòÓЩ¶´ ......
SQLPlus :http://www.orafaq.com/wiki/SQL*Plus_FAQ
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm
1. Transfer values from a sql scripts:
CNT=`sqlplus -s username/password1@dbname @getUVQuery_NULLCNT`;
Note : Remeber to use o ......