August 6, 2011

On the use of dbms_metadata.get_ddl

Filed under: Oracle — hourim @ 3:48 pm

A question recently came into an oracle French forum (http://www.developpez.net/forums/d1117051/bases-donnees/oracle/source-vue-format-text/)  asking about how to get a DDL of views containing a given text

I thought it is worth writing here the English translation of my French answer to that thread. I will start by creating a view in which I will use the term ‘Mohamed’


mhouri.world> create view view_test as
2  select *
3  from emp
4  where ename = 'Mohamed';
View created.

And now we would like to get views that contains the text ‘Mohamed’ in their DDL creation script.


mhouri.world> SELECT *
2    FROM
3    (SELECT
4           dbms_metadata.get_ddl('VIEW', view_name) txt
5     FROM  user_views
6    ) ww
7  WHERE
8     dbms_lob.instr (ww.txt, 'Mohamed') != 0
9  ;

CREATE OR REPLACE FORCE VIEW "MHOURI"."VIEW_TEST" ("EMPNO", "ENAME", "JOB", "MGR
", "HIREDATE", "SAL", "COMM", "DEPTNO") AS
select "EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO"
from emp
where ename = 'Mohamed'

Hope this will help.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Get a blog at WordPress.com

Follow

Get every new post delivered to your Inbox.