Oracle 페이지 나누기 공통 스토리지 프로세스

2068 단어 데이터베이스
create or replace package page is   
type type_cur is ref cursor;   
procedure p_pagintion   
(   
       psql in varchar2,       --  SQL     
       pfrist in number,       --      
       psize in number,        --          
       pcount out number,      --      
       pnotecount out number,  --      
       pnote out type_cur      --         
);   
END;   
/  
create or replace package body page is   
  
procedure p_pagintion   
(   
       psql in varchar2,       --  SQL     
       pfrist in number,       --      
       psize in number,        --          
       pcount out number,      --      
       pnotecount out number,  --      
       pnote out type_cur      --         
)   
AS   
v_pfrist number;   
v_sql varchar2(4000);   
v_sql1 varchar2(4000);   
v_sql2 varchar2(4000);   
v_sql3 varchar2(4000);   
v_notecount number;   
v_min number;   
v_max number;   
BEGIN   
            v_sql:='select count(*) from (' || Psql || ')';--      SQL   
            execute immediate v_sql into v_notecount;--  SQL           
            pnotecount:=v_notecount;   
            pcount:=ceil(pnotecount/psize);--        
            v_pfrist:=pfrist;   
            IF(v_pfrist > pcount)THEN   
            v_pfrist:=pcount; --               ,             
            end IF;   
            v_max:=v_pfrist*psize;--              
            v_min:=v_max-psize+1;--              
            v_sql1:='select * from (select rownum rn,t.* from ';   
            v_sql2:=' t ) where rn between '||v_min||' and '||v_max;   
            v_sql3:=v_sql1||' ( '||psql||' ) '||v_sql2;--  SQL   
            open pnote for v_sql3;   
END p_pagintion;   
END page;   
/  
 

좋은 웹페이지 즐겨찾기