Avoid over-dependence on SQL*Plus with the Group By and Rollup SQL commands (8i+)



Request Information

Want more information? Fill out the form below and we'll contact you shortly.

Name

Phone

Email

Subject

Message




Date : 7/13/2010

While the SQL*Plus language is an invaluable tool, it’s important not to get so dependent on it that you forget what to do if it isn’t available. For example, following is a nifty script that computes the amount of storage space (in bytes) taken up by your own database objects, such as tables or indexes. The script is composed of two parts. The first three lines are SQL*Plus commands. The next two lines make up the SQL query.

column sum(bytes) heading BYTES format 999,999
compute sum of bytes on report
break on report skip 1
select segment_name,bytes
from user_segments

If you run these lines in SQL*Plus or iSQL*Plus, the output appears like this:

SEGMENT_NAME BYTES
---------------- --------
DEPT 65,536
EMP 65,536
--------
sum 131,072

But if you type this script in HTML DB, JDeveloper’s SQL Worksheet, Enterprise Manager’s SQL Scratchpad, or some non-Oracle application, you’ll probably get the error message ORA-00900: invalid SQL statement because of the three SQL*Plus commands at the top.

Fortunately, SQL is more powerful today than it was when SQL*Plus was originally designed. You can produce approximately the same report with straight SQL, as shown here:

select segment_name,
to_char(sum(bytes),'999G999') as BYTES
from user_segments
group by rollup (segment_name)

SEGMENT_NAME BYTES
---------------- --------
DEPT 65,536
EMP 65,536
131,072

 


Previous News: 7/6/2010

Don't burden web visitors with video when text would do

Don’t let fancy CLR debugging slow you down

Easily enter numeric characters as text strings (Excel 2000/2002/2003/2004/2007)

Implement the best security measures—with the right guidance

Pique people's interest when writing for the web

Using your own sound effects in Microsoft PowerPoint slides (2002/2003/2007)

Same Day

Control the style of links with CSS pseudo-classes

Create hyperlinks that point to areas in a workbook (Excel 2000/2002/2003/2004/2007)

Option Strict places an even tighter grip on applications (VB .NET)

Perform fail-safe firmware upgrades

Print certain slides as handouts (PowerPoint 2000/2002/2003/2004/2007)

Next News: 7/20/2010

Avoid misconceptions about SQL injection attacks

Avoid the hassle of escaping quotes with user-defined quotes

Create standalone software packages with the Microsoft Access Runtime

Never hit the wrong database again in the Query window

Remove a sender from your Outlook junk e-mail list (2003/2007)

Split your screen using only the keyboard (Word 2000/2002/2003/2004/2007)

Share |
Since 1982, New Horizons Computer Learning Centers has grown to become the largest independent IT training company worldwide. We offer more courses, at more times and in more locations than any other computer and business training company. Businesses and individuals can choose from hundreds of course offerings, delivered by experts, and offered in hundreds of convenient locations around the world.


Albany, NY
(518) 452-6444
10 Airline Drive, Ste 101
Albany, NY 12205
Charlotte, NC
(704) 522-9747
9140 Arrowpoint Blvd, Ste 400
Charlotte, NC 28273
Harrisburg, PA
5095 Ritter Road, Ste 114
Mechanicsburg, PA 17055
Lancaster, PA
(717) 791-0200
1020 New Holland Ave
Lancaster, PA 17601