When using Toad to create a view in Oracle, how can I save a formatted script as well?

This question may be specific to the toad. I have no idea how Oracle stores views, so I will explain what happens when I use Toad. If I get an Oracle-specific answer, all the better.

I created a rather complex view. To make it clearer, I formatted the code well and introduced some comments where necessary. When I need to make changes to a view, I use the "Describe Objects" window, where I can find a script to recreate the view. The only problem is that all my formatting has disappeared. Comments before the select keyword (but after "create view xxx as") will also disappear.

If I enter this script to create a view:

create or replace view TestViewFormatting as -- Here I have a long comment explaining the role of the -- view and certain things to be aware of if changing it. -- Unfortunately this comment will disappear... select name, --This comment will be kept accountnumber --This also from debtable where name like 'S%'; 

Toad will display this when I describe it later:

 DROP VIEW XXX.TESTVIEWFORMATTING; /* Formatted on 04.07.2012 09:35:45 (QP5 v5.185.11230.41888) */ CREATE OR REPLACE FORCE VIEW XXX.TESTVIEWFORMATTING ( NAME, ACCOUNTNUMBER ) AS select name, --This comment will be kept accountnumber --This also from debtable where name like 'S%'; 

Please note that the first comment has disappeared and the format is completely different.

I suspect that Oracle does not store the view code, but only some collapsible version, and when Toad calls the script, it changes that collapsible version and generates the script on the fly.

What do I need to do to get Toad / Oracle to keep the original formatting?

(PS: I know that I can change the formatting settings of the toad code, but this is not what I want to do. Due to some dubious choices in my past, this particular view has several levels of inline views, and I need very specific formatting to make it clear what is happening)

+4
source share
2 answers
 select text from user_views where view_name = 'YOUR_VIEW_NAME'; 

I tested with:

 create view z_v_test as select -- te --st * from dual; 

and it saves even an empty string.

+4
source

Another way is to use DBMS_METADATA:

 select dbms_metadata.get_ddl('VIEW', 'YOUR_VIEW_NAME', user) from dual 

This works not only for views, but also for (almost) all types of database objects (tables, triggers, functions, ...).

+2
source

All Articles