15.01.2013 Views

Oracle Database 11g The Complete Reference (Osborne ORACLE ...

Oracle Database 11g The Complete Reference (Osborne ORACLE ...

Oracle Database 11g The Complete Reference (Osborne ORACLE ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

98 Part II: SQL and SQL*Plus<br />

4<br />

5<br />

6<br />

7<br />

8<br />

relabels the column and gives it a new heading. This heading breaks into two lines because it has<br />

the headsep character (!) embedded in it. <strong>The</strong> line<br />

column Name format a20<br />

at Circle 4 sets the width for the Name column’s display at 20. <strong>The</strong> a tells SQL*Plus that this is an<br />

alphabetic column, as opposed to a numeric column. <strong>The</strong> width can be set to virtually any value,<br />

irrespective of how the column is defined in the database.<br />

<strong>The</strong> Name column is defined as 25 characters wide, so it’s possible that some names will<br />

have more than 20 characters. If you did nothing else in defining this column on the report, any<br />

name more than 20 characters long would wrap onto the next line. Looking at Figure 6-2 again,<br />

you can see that four of the titles have wrapped; the Title column is defined as VARCHAR2(100)<br />

but is formatted as a20 (see Circle 5).<br />

Instead of using the word_wrapped format, you could choose truncated, eliminating the<br />

display of any characters that exceed the specified format length for the column.<br />

Circle 6 in Figure 6-3 shows an example of formatting a number:<br />

column DaysOut format 999.99<br />

This defines a column with room for five digits and a decimal point. If you count the spaces in<br />

the report for the DaysOut column, you’ll see seven spaces. Just looking at the column command<br />

might lead you to believe the column would be six spaces wide, but this would leave no room<br />

for a minus sign if the number were negative, so an extra space on the left is always provided for<br />

numbers.<br />

Circle 7 in Figure 6-3 refers to a column that didn’t appear in the table when we had<br />

SQL*Plus describe it:<br />

column DaysOut heading 'Days!Out'<br />

What is DaysOut? Look at the select statement at the bottom of Figure 6-3. DaysOut appears<br />

in the following line:<br />

ReturnedDate-CheckoutDate as DaysOut /*Count Days*/<br />

This tells SQL to perform date arithmetic—count the number of days between two dates—and<br />

give the computation a simpler column name. As a consequence, SQL*Plus sees a column named<br />

DaysOut, and all its formatting and other commands will act as if it were a real column in the<br />

table. <strong>The</strong> column command for DaysOut is an example. “DaysOut” is referred to as a column<br />

alias—another name to use when referring to a column.<br />

break on<br />

Look at Circle 8 in Figure 6-3. Note on the report in Figure 6-2 how the checkout records for each<br />

name are grouped together. This effect was produced by the line<br />

break on Name skip 1 on report<br />

as well as by the line<br />

order by Name, CheckoutDate;<br />

in the select statement near the end of the start file.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!