Some time ago, someone at my work created a new View in our Oracle database called AUTORESUZ
(notice the capitals!) and I wanted to know how this view was defined, this is, the query that lies under it.
You can list all the views defined at your Oracle database by having a look at all_views
table which stores the following information of each view:
SQL> DESC all_views; Name NULL? TYPE ----------------------------------------- -------- ---------------------------- OWNER NOT NULL VARCHAR2(30) VIEW_NAME NOT NULL VARCHAR2(30) TEXT_LENGTH NUMBER TEXT LONG TYPE_TEXT_LENGTH NUMBER TYPE_TEXT VARCHAR2(4000) OID_TEXT_LENGTH NUMBER OID_TEXT VARCHAR2(4000) VIEW_TYPE_OWNER VARCHAR2(30) VIEW_TYPE VARCHAR2(30) SUPERVIEW_NAME VARCHAR2(30) |
The query information is stored in “text” row. So, let’s retrieve the query that our AUTORESUZ has defined:
SQL> SELECT text FROM all_views WHERE view_name = 'AUTORESUZ'; TEXT ---------- SELECT a1. |
OMFG! The query seems to be there, but it is truncated…
In order to view the full query, you must set long with a value greater that text’s length. Like this:
SQL> SELECT text_length FROM all_views WHERE view_name = 'AUTORESUZ'; TEXT_LENGTH ----------- 369 SQL> SELECT text FROM all_views WHERE view_name = 'AUTORESUZ'; TEXT ---------- SELECT a1. SQL> SET long 369 SQL> SELECT text FROM all_views WHERE view_name = 'AUTORESUZ'; TEXT -------------------------------------------------------------------------------- SELECT a1.rec_key AS arecord, REGEXP_REPLACE(a2.rec_data,'^\|a(.*)','\1') AS nipuz, REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(a1.rec_data,'^\|a(.*)\|6\(UZ.*',' \1'), '(.*)\|c(.*)','\1'), '(.*),\|d(.*)','\1') AS autoruz FROM var_fields2 a1, var_fields2 a2 WHERE a1.rec_key LIKE 'a%' AND a1.MARC_TAG='100' AND (a1.rec_key=a2.rec_key AND a2.MARC_TAG='090') |