Exporting DDL of all views Oracle

ddloracleoracle-9i

How can I go about exporting DDL of all my schema views in single .sql file ?
I've read there is a function DBMS_METADATA.GET_DDL But I can't figure out how to use it for my case.

I know how to do this for one view (Oracle Entreprise Manager->MySchema->Views->Selecting my view->show object DDL->Save..)

I'm using SQL*Plus

Best Answer

Try this for DBMS_METADATA.GET_DLL:

set long 200000 pages 0 lines 150
spool vw.sql
select 
   dbms_metadata.GET_DDL('VIEW',u.view_name,DECODE(u.owner,'SYS','',owner)) 
from 
   all_views u
where 
   owner IN ('HR','SCOTT') 
order by owner,view_name ;
spool off

You can either include the schemas you are interested in or exclude the schemas you do not want in the "owner IN" clause.