11

My issue is I have a custom SQL runner hitting an Oracle, readonly db.

I want to get the definition of a view.

 select TEXT
 FROM all_VIEWS
 where VIEW_NAME  = '<view_name>';

This returns me limited text. A max of so many characters, maybe 100. All the views are longer than this.

The help file I found showed adding the 'set long 10000' before to capture the entire field I guess.

SQL> set long 10000

SQL> select TEXT
  2  FROM all_VIEWS
  3  where VIEW_NAME  = '<view_name>';

I don't have access to hit the set long 10000 since I'm running through another window. Is there another way to get the full definition with my limited ability?

Marmite Bomber
  • 19,886
  • 4
  • 26
  • 53
markokstate
  • 923
  • 2
  • 14
  • 28

2 Answers2

12

Your problem is the LONG column containing the view definition.

You may use the DBMS_METADATA package to get the view text as a CLOB

select DBMS_METADATA.GET_DDL ('VIEW','view_name','owner') from dual;
Marmite Bomber
  • 19,886
  • 4
  • 26
  • 53
1

Using @Marmite's suggestion of DBMS_METADATA.GET_DDL, and assuming the tool you're using only lets you retrieve 100 chars at a time, the following should retrieve your complete view:

SELECT view_name, LEVEL "Line No", 
DBMS_LOB.SUBSTR(view_clob, 100 ,1 + (LEVEL-1)*100) line_text FROM (
    SELECT view_name, owner, 
    DBMS_METADATA.GET_DDL('VIEW', view_name, owner) view_clob 
    FROM all_views WHERE view_name = '<view_name>'
) CONNECT BY LEVEL <= CEIL(LENGTHB(view_clob)/100) ORDER BY LEVEL;
Gerrat
  • 28,863
  • 9
  • 73
  • 101