Exploring Oracle Dictionary, a htmSQL Utility Hsiwei Yu, Logicon, a Northrop Grumman Company, Herndon, Virginia Wen-Hsiung Lee, U.S. Environmental Protection Agency, Washington, D.C.

ABSTRACT SQL> desc all_synonyms; Name Null? Type SAS/Access to Oracle and htmSQL, part of SAS/IntrNet, allow us to ------develop a utility for querying Oracle’s data dictionary on Internet and OWNER NOT NULL VARCHAR2(30) obtain information such as attributes in a or simple SYNONYM_NAME NOT NULL VARCHAR2(30) statistics on a column. This utility can be modified to query DB2, TABLE_OWNER VARCHAR2(30) Sybase, or ODBC-compliant database. TABLE_NAME NOT NULL VARCHAR2(30) … … INTRODUCTION htmSQL application in SAS/IntrNet was widely used for querying SAS SQL> desc all_views; data dictionary, e.g. showing variable attributes in SAS dataset. We Name Null? Type found it’s also useful to help users to explore ’s ------structure dynamically on Internet. OWNER NOT NULL VARCHAR2(30) VIEW_NAME NOT NULL VARCHAR2(30) ORACLE DATA DICTIONARY TEXT_LENGTH NUMBER Of interest for Oracle data dictionary is a named DICTIONARY, or TEXT LONG DICT. This view gives a complete list of data dictionary views. Columns … … in a data dictionary view can be further queried via the DICT_COLUMNS view. Therefore from the DICT view, we found some ARRANGE HTMSQL DRILL DOWN usage: Initially users can query all_tables to determine owners by this input hsql file: USAGE ORACLE VIEW NAME {QUERY DATASRC= ..}{SQL} Public tables for all users to read all_tables {* Oracle specific SQL statements. *} Column attribute information for all_tab_columns select owner, count(*) as counts each public table from all_tables Public synonyms for all users to all_synonyms group by owner read {/SQL} Public views for all users to read, all_views .. showing the SQL statements {EACHROW} defining each view HIERARCHY OF DICTIONARY VIEWS {&owner} From the all_tables view, there are two columns, owner and table_name. .. .. SQL> desc all_tables; {EACHROW} Name Null? Type {/QUERY} ------OWNER NOT NULL VARCHAR2(30) See Figure 1 for a sample output of owners in an Oracle TABLE_NAME NOT NULL VARCHAR2(30) instance. When an user clicks on the owner hyperlink, it will TABLESPACE_NAME VARCHAR2(30) drill down to show all the tables belonging to this owner, CLUSTER_NAME VARCHAR2(30) {QUERY DATASRC= ..}{SQL} … … {* Oracle specific SQL statements. *} select table_name, num_rows Given specific owner and table_name values, users can query the , avg_row_len all_tab_columns view to find out the corresponding column attributes from all_tables for a table owned by this owner. where owner = ‘{&owner}’ SQL> desc all_tab_columns; {/SQL} Name Null? Type .. ------{EACHROW} OWNER NOT NULL VARCHAR2(30) TABLE_NAME NOT NULL VARCHAR2(30) DATA_TYPE VARCHAR2(30) {&table_name} … …

Similarly given specific owner value, users can find out and See Figure 2 for a sample output for tables in an Oracle view owned by this owner, via Oracle’s all_synonyms and all_views. instance. COLUMN ATTRIBUTES IN A TABLE Then clicking on the table hyperlink, it will drill down to show the column attributes in a table, this paper. If SAS/Access to DB2 or Sybase licensed, or a {QUERY DATASRC= ..}{SQL} SAS/Share server running on PC environment, this utility can {* Oracle specific SQL statements. *} also be used for exploring DB2, Sybase, or ODBC-compliant select column_name, data_type .. RDBMS on Internet. from all_tab_columns where owner = ‘{&owner}’ REFERENCES and table_name = ‘{&table_name}’ Koch, G., and Loney, K., 1997. Oracle 8, the Complete {/SQL} Reference. Berkeley, CA: Osborne/McGraw-Hill .. {EACHROW} ACKNOWLEDGMENTS with this Oracle data dictionary utility. His expertise and {&column_name} enthusiasm made exploring and learning Oracle fun and exciting. See Figure 3 for sample output of columns. CONTACT INFORMATION SIMPLE STATISTICS ON A COLUMN Your comments and questions are valued and encouraged. To obtain frequency counts on a column, the following hsql source Contact the authors at: code is used: Hsiwei Yu (Michael) {QUERY DATASRC= ..}{SQL} {* Oracle specific SQL statements. *} Work Phone: 202-260-5312 select {&column}, count(*) as counts .. Email: [email protected] (H) from {&owner}.{&table} [email protected] (W) group by {&column} order by count(*) desc Wen-Hsiung Lee {/SQL} Work Phone: 202-260-5560 .. Email: [email protected] {EACHROW} {&column} {&counts} {/EACHROW} See Figure 4 for frequency counts on a column. ADAPTATION FOR OTHER RDBMS This utility works is because the htmSQL sends Oracle specific SQL statements to a SAS/Share server then than pass them to an Oracle server. SAS/Share server receives results from the Oracle server then sends them back to htmSQL for displaying on the Internet. Similarly, if SAS/Access to DB2 or Sybase licensed, or a SAS/Share server running on PC environment, the htmSQL can be used to explore DB2, Sybase, or ODBC-compliant RDMBS. For a different database system, it is necessary to find out its data dictionary equivalent in order to explore the data structure. For example, in an ODBC-compliant DBMS, the ODBC::SQLTables and ODBC::SQLColumns tables provide the data dictionary information. Regarding the input hsql source file, users can simply replace the Oracle specific SQL statements by the specific SQL required by the targeted DBMS. The following is a example for finding out existing tables in an ODBC data source:

{QUERY DATASRC= ..}{SQL} {* ODBC data source specific SQL statements. *} select table_name from ODBC::SQLTables {/SQL} .. {EACHROW} {&table_name} .. .. {EACHROW} {/QUERY}

CONCLUSION We have found the htmSQL utility was quite useful for us to gain familiarity with Oracle data. During implementation, we discovered some easy ways for exploring Oracle data structure, as described in Figure 1: Owners in an Oracle instance

Figure 2: Tables belonging to an owner Figure 3: Columns in a table

Figure 4: Column value frequency count