So we have some developers who went a little view happy. So now we have views that reference views that reference views, ad nauseum.
So what I want, in order to assist me in Tuning, is to expand these views.
I want a function that takes a string and returns a string. The input string is the query, the output string is the same query without views.
CREATE OR REPLACE VIEW myView AS
SELECT * FROM emp
Using function/stored procedure "F":
F('SELECT * FROM myView')
...would return:
SELECT * FROM ( SELECT * FROM emp)
VIEW expansion. If object used in FROM clause is object VIEW, then extract view text from database and replace view name with view text. This is an article of Oracle SQL Query rewrite serials.
An Oracle view is a validated and named SQL query stored in the Oracle Database's data dictionary. Views are simply stored queries that can be executed when needed, but they don't store data. It can be helpful to think of a view as a virtual table, or as the process of mapping data from one or more tables.
View TablesExpand the system node in Oracle SQL Developer. Expand the Other Users node and then expand the HR node. Expand the Tables (Filtered) node and select the EMPLOYEES table. Detailed information about the table is displayed in the object pane.
Short answer:
Not at this time
Not that I'm aware of
UPDATE
It looks like Oracle 12c has exactly what you need: DBMS_UTILITY.expand_sql_text
http://docs.oracle.com/cd/E16655_01/appdev.121/e17602/d_util.htm#ARPLS73973
One problem with what you are proposing is that there are usually multiple ways that a query involving views can be rewritten, so simply expanding the text of the views won't necessarily tell you a lot about how the query is being executed.
Since your purpose is tuning, I would suggest that the execution plans for the queries will probably give you the information you really need. This won't show the rewritten query, but it will show you all the actual tables and how they are referenced in executing the query.
The best way I know of to view the actual execution plan is:
SELECT /*+ gather_plan_statistics */ * FROM myView
select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With