請大家幫忙,關於儲存過程分頁的問題...謝謝
drop procedure if exists prc_page_result;
create procedure prc_page_result (
in currpage int,
in columns varchar(500),
in tablename varchar(500),
in sCondition varchar(500),
in order_field varchar(100),
in asc_field int,
in primary_field varchar(100),
in pagesize int
)
begin
declare sTemp varchar(1000);
declare sSql varchar(4000);
declare sOrder varchar(1000);
if asc_field = 1 then
set sOrder = concat(' order by ', order_field, ' desc ');
set sTemp = '<(select min';
else
set sOrder = concat(' order by ', order_field, ' asc ');
set sTemp = '>(select max';
end if;
if currpage = 1 then
if sCondition <> '' then
set sSql = concat('select ', columns, ' from ', tablename, ' where ');
set sSql = concat(sSql, sCondition, sOrder, ' limit ?');
else
set sSql = concat('select ', columns, ' from ', tablename, sOrder, ' limit ?');
end if;
else
if sCondition <> '' then
set sSql = concat('select ', columns, ' from ', tablename);
set sSql = concat(sSql, ' where ', sCondition, ' and ', primary_field, sTemp);
set sSql = concat(sSql, '(', primary_field, ')', ' from (select ');
set sSql = concat(sSql, ' ', primary_field, ' from ', tablename, sOrder);
set sSql = concat(sSql, ' limit ', (currpage-1)*pagesize, ') as tabtemp)', sOrder);
set sSql = concat(sSql, ' limit ?');
else
set sSql = concat('select ', columns, ' from ', tablename);
set sSql = concat(sSql, ' where ', primary_field, sTemp);
set sSql = concat(sSql, '(', primary_field, ')', ' from (select ');
set sSql = concat(sSql, ' ', primary_field, ' from ', tablename, sOrder);
set sSql = concat(sSql, ' limit ', (currpage-1)*pagesize, ') as tabtemp)', sOrder);
set sSql = concat(sSql, ' limit ?');
end if;
end if;
set @iPageSize = pagesize;
set @sQuery = sSql;
prepare stmt from @sQuery;
execute stmt using @iPageSize;
end;
當不加條件時正常,但一加條件,第二頁的第一條是從第一頁的第二條開始...為什麼?謝謝
create procedure prc_page_result (
in currpage int,
in columns varchar(500),
in tablename varchar(500),
in sCondition varchar(500),
in order_field varchar(100),
in asc_field int,
in primary_field varchar(100),
in pagesize int
)
begin
declare sTemp varchar(1000);
declare sSql varchar(4000);
declare sOrder varchar(1000);
if asc_field = 1 then
set sOrder = concat(' order by ', order_field, ' desc ');
set sTemp = '<(select min';
else
set sOrder = concat(' order by ', order_field, ' asc ');
set sTemp = '>(select max';
end if;
if currpage = 1 then
if sCondition <> '' then
set sSql = concat('select ', columns, ' from ', tablename, ' where ');
set sSql = concat(sSql, sCondition, sOrder, ' limit ?');
else
set sSql = concat('select ', columns, ' from ', tablename, sOrder, ' limit ?');
end if;
else
if sCondition <> '' then
set sSql = concat('select ', columns, ' from ', tablename);
set sSql = concat(sSql, ' where ', sCondition, ' and ', primary_field, sTemp);
set sSql = concat(sSql, '(', primary_field, ')', ' from (select ');
set sSql = concat(sSql, ' ', primary_field, ' from ', tablename, sOrder);
set sSql = concat(sSql, ' limit ', (currpage-1)*pagesize, ') as tabtemp)', sOrder);
set sSql = concat(sSql, ' limit ?');
else
set sSql = concat('select ', columns, ' from ', tablename);
set sSql = concat(sSql, ' where ', primary_field, sTemp);
set sSql = concat(sSql, '(', primary_field, ')', ' from (select ');
set sSql = concat(sSql, ' ', primary_field, ' from ', tablename, sOrder);
set sSql = concat(sSql, ' limit ', (currpage-1)*pagesize, ') as tabtemp)', sOrder);
set sSql = concat(sSql, ' limit ?');
end if;
end if;
set @iPageSize = pagesize;
set @sQuery = sSql;
prepare stmt from @sQuery;
execute stmt using @iPageSize;
end;
當不加條件時正常,但一加條件,第二頁的第一條是從第一頁的第二條開始...為什麼?謝謝
相關文章
- 關於資料庫的問題。請幫忙看下,在下先謝謝了資料庫
- 一個關於mysql方面的問題,希望斑竹和大家能幫忙,謝謝!!MySql
- jive配置中的database問題?!請幫忙阿謝謝!Database
- 請教關於jive原始碼,請各位高手幫忙 ,謝謝!!!原始碼
- benq大哥,幫忙,請進入,謝謝!ENQ
- 回覆: 求一個關於排期的儲存過程, 感謝大家儲存過程
- 關於jsp拒絕訪問的問題,謝謝大家JS
- 分頁Bean的同步問題,,請大家幫忙解決Bean
- 請幫我看看呼叫webservice的問題謝謝!Web
- 關於領域驅動設計與開發過程中的一些疑惑請道友幫忙解惑,謝謝。
- 有關javaAPI,請各位高手幫忙,拜謝JavaAPI
- Jdon版jive安裝過程中,mysql資料庫連線出錯!(請幫幫忙,謝謝!)MySql資料庫
- 請教彭老師關於jdbc的問題,謝謝!JDBC
- 關於SimpleJdonFrameworkTest的問題,謝謝!Framework
- 關於petstore的執行問題,謝謝~
- 請求幫助!謝謝!
- jms的問題,請高手幫忙解決一下,先謝了
- Oracle在UNIX上實施的新書就要面市,還請大家幫忙看看,書名怎麼定合適?謝謝大家!Oracle新書
- 關於mysql和jsp的中文問題~謝謝MySqlJS
- 急不理解的問題,大家幫幫忙,關於jive
- 謝謝斑竹能否幫個忙!! (改個小程式)
- 請高手幫忙了,關於javamail的問題JavaAI
- 有關單體模式設計的問題,請大家幫忙模式
- 關於有狀態BEAN如何透過關鍵字儲存使用者狀態的問題,請幫忙Bean
- 請問哪裡有關於java播放Flash的例子啊?謝謝了Java
- 安裝是遇到錯誤,大家幫我看看,謝謝
- activemq的問題,謝謝MQ
- 基於ROWCOUNT的分頁儲存過程儲存過程
- 幫忙看看如何設定,跪謝!
- 高手幫忙解決兩道JAVA題,跪謝!!Java
- 求助!關於執行緒的問題?各位大俠謝謝了!!!執行緒
- 關於servlet多執行緒序的疑問,請各位仁兄作答,謝謝。Servlet執行緒
- 分頁儲存過程儲存過程
- 關於 Appium 中 ios 自動化測試的幾個問題,請教下大神,謝謝APPiOS
- 請教tomcat連線sqlserver的問題!!謝謝各位!TomcatSQLServer
- 請問可以使用jacob操作WORD文件的頁首頁尾嗎?謝謝!
- 關於反射的問題,請高手幫忙!線上急等!反射
- 關於digest認證的問題,請高手幫忙