PROCEDURE xxx(
pi_current IN INTEGER, --dannaja stranica
pi_per_page IN INTEGER, --kol-vo na str
pi_order IN VARCHAR2, --asc or desc
po_found OUT INTEGER,
mycurs OUT TYPES.cursorType
)
IS
BEGIN
SELECT COUNT(*)
INTO po_found
FROM TABLE
WHERE xxx;
OPEN mycurs FOR
SELECT * FROM(
SELECT ROWNUM num_id, --!
TABLE.*
FROM TABLE
)
WHERE num_id >= NAVIGATION('start',pi_order,pi_current,pi_per_page,po_found)
AND num_id <= NAVIGATION('end',pi_order,pi_current,pi_per_page,po_found)
;
END; -- Procedure
FUNCTION NAVIGATION(
pi_type IN VARCHAR2, -- 'start'||'end'
pi_order IN VARCHAR2, -- desc||asc
pi_current IN INTEGER,
pi_per_page IN INTEGER,
pi_found in integer
)
RETURN INTEGER IS
end_r INTEGER;
start_r INTEGER;
p_current INTEGER;
p_max INTEGER;
BEGIN
if(pi_order = 'desc')then
p_max := CEIL(pi_found/pi_per_page);
IF(pi_current = 0)THEN
p_current := p_max;
else
p_current := pi_current;
END IF;
IF(p_current = p_max) THEN
end_r := pi_found;
ELSE
end_r := pi_found-(pi_per_page*(p_max-p_current));
END IF;
IF(p_current = p_max) THEN
start_r := pi_found-pi_per_page+1;
ELSIF(p_current = 1) THEN
start_r := 1;
ELSIF(p_current != 1) THEN
start_r := end_r-pi_per_page+1;
END IF;
IF(p_max = 0) THEN
start_r := 0;
end_r := pi_per_page;
END IF;
else
IF(pi_current = 0)THEN
p_current := 1;
else
p_current := pi_current;
END IF;
IF(p_current != 1)THEN
end_r := p_current*pi_per_page;
ELSE
end_r := pi_per_page;
END IF;
IF(p_current != 1)THEN
start_r := (p_current-1)*pi_per_page+1;
ELSE
start_r := 1;
END IF;
end if;
if(pi_type = 'start')then
return start_r;
else
return end_r;
end if;
END;