We can limit no of rows from result using rownum clause
select * from
(
select val from mytable
) where rownum<=5
If we want first or last record then we want order by clause in inner query that will give result based on order.
Last Five Record :
select * from
(
select val from mytable order by val desc
) where rownum<=5
First Five Record
select * from
(
select val from mytable order by val
) where rownum<=5