Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Limiting the number of rows retrieved

507916Feb 17 2011 — edited Feb 17 2011
We have the need of limiting the number of rows retrieved from a table to some users.

We have tried to set this by adding a policy that limits the number of rows. Here is the code:


create or replace function
usu01_access_policy
(obj_schema varchar2, obj_name varchar2) return varchar2
is
d_predicate varchar2(2000);
begin
if user = 'PEPE01' then
d_predicate:=
'rownum < 11';
else
d_predicate:=
'1 = 1';
end if;
return d_predicate;
end;

This code is working ok when querying the table like this:

select * from usu01;

the number of rows retrieved is 10.

But when we define a 'where' clause, the query only applies the clause to the 10 rows retrieved before, getting only the rows of the first 10 with the 'where' condition=true.

Is there a way to limit the number of rows retrieved from a table, but applying first the 'where' clause to the whole table and later the 'rownum < limit' condition?

Thanks
This post has been answered by Nicolas Gasparotto on Feb 17 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2011
Added on Feb 17 2011
5 comments
320 views