Download Exploring Oracle.... Data Dictionary, a htmSQL.... Utility

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Expense and cost recovery system (ECRS) wikipedia , lookup

Microsoft Access wikipedia , lookup

Information privacy law wikipedia , lookup

Database wikipedia , lookup

Business intelligence wikipedia , lookup

Clusterpoint wikipedia , lookup

Data vault modeling wikipedia , lookup

SAP IQ wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Oracle Database wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Exploring Oracle Data 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
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
obtain information such as column attributes in a table or simple
statistics on a column. This utility can be modified to query DB2,
Sybase, or ODBC-compliant database.
SQL> desc all_synonyms;
Name
Null?
-------------------- -------OWNER
NOT NULL
SYNONYM_NAME
NOT NULL
TABLE_OWNER
TABLE_NAME
NOT NULL
… …
Type
---VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
INTRODUCTION
htmSQL application in SAS/IntrNet was widely used for querying SAS
data dictionary, e.g. showing variable attributes in SAS dataset. We
found it’s also useful to help users to explore Oracle database’s
structure dynamically on Internet.
ORACLE DATA DICTIONARY
Of interest for Oracle data dictionary is a view named DICTIONARY, or
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
usage:
USAGE
Public tables for all users to read
Column attribute information for
each public table
Public synonyms for all users to
read
Public views for all users to read,
showing the SQL statements
defining each view
ORACLE VIEW NAME
all_tables
all_tab_columns
all_synonyms
all_views
HIERARCHY OF DICTIONARY VIEWS
From the all_tables view, there are two columns, owner and
table_name.
SQL> desc all_tables;
Name
Null?
Type
------------------------------- -------- ---OWNER
NOT NULL VARCHAR2(30)
TABLE_NAME
NOT NULL VARCHAR2(30)
TABLESPACE_NAME
VARCHAR2(30)
CLUSTER_NAME
VARCHAR2(30)
… …
SQL> desc all_views;
Name
-------------------OWNER
VIEW_NAME
TEXT_LENGTH
TEXT
… …
Null?
-------NOT NULL
NOT NULL
Type
---VARCHAR2(30)
VARCHAR2(30)
NUMBER
LONG
ARRANGE HTMSQL DRILL DOWN
Initially users can query all_tables to determine owners by
this input hsql file:
{QUERY DATASRC= ..}{SQL}
{* Oracle specific SQL statements. *}
select owner, count(*) as counts
from all_tables
group by owner
{/SQL}
..
{EACHROW}
<TR>
<TD>
<A HREF=”tables.hsql?owner={&owner}&..”>
{&owner}
</A>
.. ..
{EACHROW}
{/QUERY}
Given specific owner and table_name values, users can query the
all_tab_columns view to find out the corresponding column attributes
for a table owned by this owner.
SQL> desc all_tab_columns;
Name
Null?
Type
------------------------------- -------- ---OWNER
NOT NULL VARCHAR2(30)
TABLE_NAME
NOT NULL VARCHAR2(30)
COLUMN_NAME
NOT NULL VARCHAR2(30)
DATA_TYPE
VARCHAR2(30)
… …
See Figure 1 for a sample output of owners in an Oracle
instance. When an user clicks on the owner hyperlink, it will
drill down to show all the tables belonging to this owner,
{QUERY DATASRC= ..}{SQL}
{* Oracle specific SQL statements. *}
select table_name, num_rows
, avg_row_len
from all_tables
where owner = ‘{&owner}’
{/SQL}
..
{EACHROW}<TR>
<TD>
<A HREF=”columns.hsql?owner={&owner}
&table={&table_name}&..”>
{&table_name}
</A>
Similarly given specific owner value, users can find out synonym and
view owned by this owner, via Oracle’s all_synonyms and all_views.
See Figure 2 for a sample output for tables in an Oracle
instance.
COLUMN ATTRIBUTES IN A TABLE
Then clicking on the table hyperlink, it will drill down to show
the column attributes in a table,
{QUERY DATASRC= ..}{SQL}
{* Oracle specific SQL statements. *}
select column_name, data_type ..
from all_tab_columns
where owner = ‘{&owner}’
and table_name = ‘{&table_name}’
{/SQL}
..
{EACHROW}<TR>
<TD>
<A HREF=”freq.hsql?owner={&owner}
&table={&table_name}
&column={&column_name}&..”>
{&column_name}
</A>
See Figure 3 for sample output of columns.
SIMPLE STATISTICS ON A COLUMN
To obtain frequency counts on a column, the following hsql source
code is used:
{QUERY DATASRC= ..}{SQL}
{* Oracle specific SQL statements. *}
select {&column}, count(*) as counts ..
from {&owner}.{&table}
group by {&column}
order by count(*) desc
{/SQL}
..
{EACHROW}<TR>
<TD>{&column}</TD>
<TD>{&counts}</TD>
</TR>
{/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}
<TR>
<TD>
{&table_name}
</TD>
.. ..
{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
this paper. If SAS/Access to DB2 or Sybase licensed, or a
SAS/Share server running on PC environment, this utility can
also be used for exploring DB2, Sybase, or ODBC-compliant
RDBMS on Internet.
REFERENCES
Koch, G., and Loney, K., 1997. Oracle 8, the Complete
Reference. Berkeley, CA: Osborne/McGraw-Hill
ACKNOWLEDGMENTS
Hsiwei Yu like to thank Mr. Gray Fernandez of Lockheed
Martin, of Research Triangle Park, NC, for his generous help
with this Oracle data dictionary utility. His expertise and
enthusiasm made exploring and learning Oracle fun and
exciting.
CONTACT INFORMATION
Your comments and questions are valued and encouraged.
Contact the authors at:
Hsiwei Yu (Michael)
Work Phone: 202-260-5312
Email: [email protected] (H)
[email protected] (W)
Wen-Hsiung Lee
Work Phone: 202-260-5560
Email: [email protected]
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