posts - 495,comments - 227,trackbacks - 0
          一 oracle
          CREATE OR REPLACE PROCEDURE page(
          ??? p_num integer,
          ??? p_size integer,
          ??? condition clob,
          ??? table_name varchar,
          ??? p_rowset out sys_refcursor)
          AS
          BEGIN
          OPEN p_rowset FOR
          ??? 'SELECT *
          ??????? FROM (
          ??????????? SELECT ROWNUM r, t1.*
          ??????????????? FROM (
          ??????????????????? SELECT '|| table_name || '.* FROM '|| table_name || ' '?
          ????????????????????? || condition || 'ORDER BY happentime desc) t1
          ?????????????? WHERE ROWNUM <= ' || p_size*p_num || ' ) t2
          ??????? WHERE t2.r > ' || p_size*(p_num-1);
          END PAGE;

          二 mssql
          CREATE PROCEDURE page
          ??? @p_num int,
          ??? @p_size int,
          ??? @condition text,
          ??? @table_name nvarchar(100),
          ??? @current_page_size int
          AS
          if @p_num = 1
          ?? execute('SELECT TOP '+ @p_size +' * FROM '+ @table_name + ' '+ @condition +' ORDER BY happentime DESC')
          else
          ?? if @current_page_size != @p_size
          ????? execute('SELECT * FROM(
          ??????????????????? SELECT TOP '+ @current_page_size +' * FROM '+ @table_name + ' '+ @condition +' ORDER BY happentime
          ????????????? ) as t ORDER BY happentime DESC')
          ?? else
          ????? begin
          ????? declare @tmp int
          ????? set @tmp = @p_size * @p_num
          ????? execute('SELECT * FROM(
          ??????????????????? SELECT TOP '+ @p_size +' * FROM(
          ???????????????????????? SELECT TOP '+ @tmp +' * FROM '+ @table_name + ' '+ @condition +' ORDER BY happentime DESC
          ??????????????????? ) AS t1 ORDER BY happentime
          ????????????? ) as t2 ORDER BY happentime DESC')
          ????? end
          GO

          三 sybase
          CREATE PROCEDURE page
          ??? @p_num int,
          ??? @p_size int,
          ??? @condition? nvarchar(3000),
          ??? @table_name nvarchar(100),
          ??? @current_p_size int
          AS
          DECLARE @str_p_size varchar(20),
          ??????? @str_tmp varchar(20),
          ??????? @str_current_p_size varchar(20),
          ???? @i_rowcount?int?
          begin
          ?select @str_tmp=cast(@p_size * @p_num as varchar(20))
          ?select @str_p_size=cast(@p_size as varchar(20))
          ?select @str_current_p_size=cast(@current_p_size as varchar(20))
          ?
          ?if @p_num = 1
          ??begin
          ???set @i_rowcount=@p_size*@p_num
          ???set rowcount @i_rowcount
          ???execute('SELECT? * FROM '+ @table_name + ' '+ @condition +' ORDER BY happentime DESC')
          ??end
          ?else
          ??if @current_p_size != @p_size
          ???begin
          ????set rowcount @current_p_size
          ????execute('SELECT? * INTO #temp FROM '+ @table_name + ' '+ @condition +' ORDER BY happentime?
          ??????????? ?SELECT * FROM #temp ORDER BY happentime DESC')
          ???end
          ??else
          ???begin
          ????set @i_rowcount=@p_size*@p_num
          ????set rowcount @i_rowcount
          ????execute('SELECT? * INTO #temp1 FROM '+ @table_name + ' ' + @condition +' ORDER BY happentime DESC
          ????? ?SELECT TOP '+ @str_p_size + ' * INTO #temp2 FROM #temp1 ORDER BY happentime
          ????? ?SELECT * FROM #temp2 ORDER BY happentime DESC')
          ???end
          end
          posted on 2006-05-26 11:02 SIMONE 閱讀(372) 評論(0)  編輯  收藏 所屬分類: 收藏
          主站蜘蛛池模板: 天门市| 平山县| 怀化市| 双柏县| 图们市| 青浦区| 泸定县| 肥城市| 比如县| 安国市| 鞍山市| 江川县| 深水埗区| 望奎县| 缙云县| 汨罗市| 山东省| 泌阳县| 石首市| 乐平市| 无极县| 绍兴市| 新乡市| 恭城| 拉萨市| 塘沽区| 天祝| 白沙| 梁平县| 安图县| 柳江县| 福建省| 云南省| 绍兴市| 尉氏县| 房山区| 黄骅市| 婺源县| 蒙城县| 夏邑县| 津市市|