Oracle SQL Developer - How to generate script in correct order of dependencies

2.2k Views Asked by At

I would want to generate create script that will create all the database views which are very many. I know how to do it in Oracle SQL Developer already using menu: Tools > Database Exports. However I encounter issues doing the export create views scripts. Below are the issues.

Issue #1 The order of creation of view is not correct. In example below, the MY_VIEW_B is created first in the script before its dependency MY_VIEW_A. How can I generate script that are in correct order of dependencies?

CREATE OR REPLACE MY_VIEW_B ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM MY_VIEW_A;

CREATE OR REPLACE MY_VIEW_A ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_A;

Issue #2 The semicolon ";" is carried over to the last line of the view codes but the problem is it is comment line. So this will get error when I execute the script because there is no closing ";" semicolon since it was moved to the line where the comment is. How can I generate script so that the last line of my view code which is ";" semicolon is not auto carried over to second to the last line of the view code which is a comment?

CREATE OR REPLACE MY_VIEW_C ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_B
--THIS IS A COMMENT;

CREATE OR REPLACE MY_VIEW_C ("COLUMN1", "COLUMN2") AS
SELECT "COLUMN1", "COLUMN2"
FROM TABLE_C;

Thank you.

1

There are 1 best solutions below

5
On

As Oracle States here:

FORCE

Specify FORCE if you want to create the view regardless of whether the base tables of the view or the referenced object types exist or the owner of the schema containing the view has privileges on them. These conditions must be true before any SELECT, INSERT, UPDATE, or DELETE statements can be issued against the view.

If the view definition contains any constraints, CREATE VIEW ... FORCE will fail if the base table does not exist or the referenced object type does not exist. CREATE VIEW ... FORCE will also fail if the view definition names a constraint that does not exist.

also check Terminator and Pretty Print to deal with the second issue;

enter image description here

Tested with Oracle SQL Developer Version 4.1.3.20 Build MAIN-20.78