
2008-7-4 13:55
judeke_itpub
关于分页绑定变量的问题
我在过程中实现分页:
create or replace procedure proc_jqyx_int_getcountsdetail(
sqlscript varchar2, --表名/SQL语句
pageSize integer, --每页记录数
currentPage integer, --当前页
totalCount out number, --总记录数
totalPage out number, --总页数
v_cur out sys_refcursor --返回游标数据集
) is
v_PageSize number;
v_currentPage number;
v_SQL_Count varchar2(4000);
v_SQL varchar2(4000);
v_StartPage number;
v_EndPage number;
begin
v_PageSize:=pageSize;
if v_PageSize=0 then
v_PageSize:=1;
end if;
--统计记录数量
v_SQL_Count := 'select count(*) from ('|| sqlscript ||') a ';
execute immediate v_SQL_Count into totalCount;
--计算总页数
totalPage:=CEIL(totalCount/v_PageSize);
--验证页号 如果页号大余了最大页数,返回最后一页
v_currentPage:=currentPage;
if v_currentPage>totalPage then
v_currentPage:=totalPage;
end if;
--计算开始的Page和结束的Page
v_StartPage:=(v_currentPage-1)*v_PageSize+1;
v_EndPage:=v_currentPage*v_PageSize;
v_SQL:='SELECT /*+ FIRST_ROWS */* FROM (';
v_SQL:=v_SQL||' SELECT A.*, ROWNUM RN ';
v_SQL:=v_SQL||' FROM ('||sqlscript||') A ';
v_SQL:=v_SQL||' WHERE ROWNUM <= '||v_EndPage;
v_SQL:=v_SQL||')WHERE RN >= '||v_StartPage;
open v_cur for v_SQL;
end proc_jqyx_int_getcountsdetail;
但是此处的变量v_StartPage和v_EndPage在存储过程中赋值后传入
v_SQL:='SELECT /*+ FIRST_ROWS */* FROM (';
v_SQL:=v_SQL||' SELECT A.*, ROWNUM RN ';
v_SQL:=v_SQL||' FROM ('||sqlscript||') A ';
v_SQL:=v_SQL||' WHERE ROWNUM <= '||v_EndPage;
v_SQL:=v_SQL||')WHERE RN >= '||v_StartPage;
就不是一个绑定变量的sql.当每次分页都会解析以便这个sql.不知道大家是怎么处理分页的?
调整cursor_sharing参数因该可以解决这个问题 但是如果我不调整数据参数只在过程中做文章行不行?
2008-7-4 14:13
DragonBill
open cursor for sql_statement using bind_variable...
2008-7-4 14:51
judeke_itpub
谢谢!解决了!
2008-7-4 15:07
jvkojvko
方法贴出来让我学习下a
2008-7-4 15:31
judeke_itpub
当我要传多个参数的时候呢
open v_cur for v_SQL using v_StartPage,v_EndPage;
这样好像不行.
2008-7-4 22:28
newkid
谁说多个参数不行?你的 V_SQL 要按顺序加入 :v_StartPage, :v_EndPage,
然后OPEN的时候 USING 绝对是可以的。
2008-7-5 12:28
ispu
type ee is ref cursor;
v_cu ee;
begin
open v_cu for 'select a from b where c=:x where d > date'2008-1-1'' using v_int;
loop
fetch v_cu into v_date;
exit when v_cu%notfound;
2008-7-7 20:01
owlstudio
正解!
2008-7-8 10:19
zhouwf0726
execute immediate '... :1,:2' using var_1,var_2;
页:
[1]

Powered by ITPUB论坛