在后台扩展每个 select 查询

Extend every select query in the background

是否可以扩展数据库用户执行的每个 select 查询?

例如用户将执行 select * from mytable 并在后台执行以下操作: select * from mytable union all select * from different_schema.mytable

可以使用 VPD 函数通过动态 where 子句限制查询。

return '1=1'

我能否将使用 VPD 的查询扩展到 select 来自不同模式的数据?

return '1=1 union all select * from different_schema.' || tab;

上面的示例出现以下错误:

ORA-28113: policy predicate has error

一种解决方法是创建一组动态生成的包含联合的视图,但我想尽可能使用 VPD 或类似方法。

不,您不能使用 VPD 执行此操作。 VPD 会在每个查询中添加一个predicate,这是对查询的where 子句的扩展。它不能用于 union 和另一个 table。

我建议您采用其他方法:使用包含联合的视图并授予对这些视图的适当权限,而不是基础 table(s)。