Using Oracle in-line views

The inline view is a construct in Oracle SQL where you can place a query in the SQL FROM, clause, just as if the query was a table name. A common use for in-line views in Oracle SQL is to simplify complex queries by removing join operations and condensing several separate queries into a single query. The best example of the in-line view is the common Oracle DBA script that is used to show the amount of free space and used space within all Oracle tablespaces. Let’s take a close look at this SQL to see how it works. Carefully note that the FROM clause in this SQL query specifies two sub-queries that perform summations and grouping from two views, dba_data_files, and dba_free_space. In ANSI standard SQL, it is quite difficult to compare two result sets that are summed together in a single query, and this is a common problem with Oracle SQL where specific values must be compared to a summary. Without the use of an in-line view, several separate SQL queries would need to be written, one to compute the sums from each view and another to compare the intermediate result sets. This is a great report for display the actual amount of free space within an Oracle tablespace.
column "Tablespace" format a13 column "Used MB" format 99,999,999 column "Free MB" format 99,999,999 colimn "Total MB" format 99,999,999 select fs.tablespace_name (df.totalspace - fs.freespace) fs.freespace df.totalspace round(100 * (fs.freespace / df.totalspace)) from (select tablespace_name, round(sum(bytes) / 1048576) TotalSpace from dba_data_files group by tablespace_name ) df, (select tablespace_name, round(sum(bytes) / 1048576) FreeSpace from dba_free_space group by tablespace_name ) fs where df.tablespace_name = fs.tablespace_name;

"Tablespace", "Used MB", "Free MB", "Total MB", "Pct. Free"

this query needs to compare the sum of total space within each tablespace with the sum of the free space within each tablespace. by Rampant TechPress. It is only $9. http://www.rampant-books.95 and all scripts in this tips can be immediately Here is a sample of the output: Basically.This SQL quickly compares the sum of the total space within each tablespace to the sum of the free space within each tablespace.htm . See code depot for inline view examples You might also enjoy my bestselling book "Creating a Self Tuning Oracle Database".

Sign up to vote on this title
UsefulNot useful