How to Configure Oracle Row Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up oracle row level security by linking a Virtual Private Database policy to your table. This policy runs a PL/SQL function that adds a filter to every query. Teams often start with broad table permissions for shared database accounts. When a role has full table permissions, any user can read every row by default. Row filters restrict what each user sees based on their session details. This stops one department or tenant from reading another group's records. How oracle row level secur

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up oracle row level security by linking a Virtual Private Database policy to your table. This policy runs a PL/SQL function that adds a filter to every query.

Teams often start with broad table permissions for shared database accounts. When a role has full table permissions, any user can read every row by default. Row filters restrict what each user sees based on their session details. This stops one department or tenant from reading another group's records.

How oracle row level security works

The native Oracle engine enforces row rules through Virtual Private Database features. You first create an app context to hold user attributes during a session. When a user logs in, a login trigger sets values in this context. These values might include a department number, region name, or tenant ID.

Next, you write a PL/SQL function that reads this session context. The function builds and returns a text string that acts as a filter condition. You then bind this function to a table or view using the built-in policy package.

Whenever someone runs a select, update, or delete statement, the engine steps in. It calls your policy function and appends the returned condition to the statement. The user only touches rows that match the dynamic condition.

Admins can also narrow the rule down to specific columns. The policy can trigger only when a query references a sensitive column. The engine can also hide the values in those specific columns by returning null.

How to plan your policy design

Good policy design starts with a clear map of your data groups. You must pick one or two stable attributes that separate your rows. Most teams use a tenant ID or a regional code stored right on the table.

Keep your policy function logic simple and fast. The database runs this function on queries, though you can cache static results. If the function runs slow table lookups, every user query will slow down too. Read values from the memory context instead of querying other tables.

Row-Level Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Test your policies with regular user roles rather than admin accounts. Database admins often hold a bypass privilege that skips all row policies by default. If you test with an admin role, you will see all rows and miss bugs by default.

What native row policies solve and what keeps the session active

Native row policies solve data isolation inside a single shared schema. You do not need to build custom views for every user group. Because the rule sits on the table, it works across all reporting tools and SQL clients.

Still, row policies only filter which rows a statement can reach. They do not inspect what an engineer or app does with the allowed rows. A user with valid permissions can still run a bad update on their own slice of data.

Shared app service accounts also create a blind spot for native policies. If an app pools sessions under one login and skips context setup, row rules cannot tell users apart. Also, admins who hold bypass roles can still read plain text emails, phone numbers, card numbers, and national IDs across all rows by default.

Teams still need a way to check individual statements before they run. They also need field-level masking that rewrites matched fields in results for live queries.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

What is the difference between a view and Virtual Private Database?

A view requires users to query the view name instead of the base table. Virtual Private Database attaches the filter directly to the base table for every query.

Why can an admin still see all rows after I add a policy?

Accounts with the exempt policy privilege bypass all row rules by design by default. You must test and run queries with a standard role to see the filter work.

Do row policies slow down database queries?

The engine runs your policy function and adds a filter to the query plan. You can keep queries fast by caching static policy results and indexing the filtered columns.

The query runs. The emails stay hidden.