Change Oracle SQL Query Text before submission [closed]

与世无争的帅哥 提交于 2019-12-21 21:43:00

问题


Is there a advanced oracle feature to modify the SQL Query just before it is submitted to oracle? Or may be modify the result set? Based on certain condition? Like may be based on the name of the process that submits the query? Or based on the query text?

The scenario is that a process (written in C++) is running a query and we don't have a way to change the C++ code. A particular business validation within that process is failing and in order to make the validation not fail, I want a way to manipulate the returned data set or manipulate the select query just before it is submitted to oracle engine.

The C++ code is running this exact query

SELECT PL_ID FROM A_HDR WHERE ENT_NBR=''

I want to change it such that ORACLE always sees and executes the following query instead

SELECT NULL FROM A_HDR WHERE ENT_NBR=''

Please guide


回答1:


Oracle Virtual Private Database may be what you're looking for. From the manual:

Oracle Virtual Private Database (VPD) enables you to create security policies to control database access at the row and column level. Essentially, Oracle Virtual Private Database adds a dynamic WHERE clause to a SQL statement that is issued against the table, view, or synonym to which an Oracle Virtual Private Database security policy was applied.

You may be able to get the process and query text from SYS_CONTEXT. For example, sys_context('userenv', 'current_sql') and sys_context('userenv', 'module'). You may also need to use GV$SESSION to get more information.

However, I think you should try to avoid VPD if possible. It is extremely confusing to have all your SQL statements silently converted in the background. It can make development and troubleshooting very difficult.


Update

The SQL Translation Framework feature in Oracle 12c would probably be the best solution for this problem.



来源:https://stackoverflow.com/questions/12945957/change-oracle-sql-query-text-before-submission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!