Datasheet
SQL Fundamentals
15
SQL> SAVE myfile APPEND
Appended file to MYFILE.sql
SQL> @MYFILE
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- ---------
110 John Chen
EMPLOYEE_ID FIRST_NAME LAST_NAME
----------- -------------------- ---------
106 Valli Pataballa
SQL>
Saving Query Results to a File
You can use the SPOOL file na m e command to save the query results to a file. By default, the
SPOOL command creates an .lst file extension. SPOOL overwrites an existing file by default.
If you include the
APPEND option as in SPOOL file n a m e APPEND, the results are added to an
existing file. A new file will be created if the file does not exist already.
SPOOL OFF stops writing the output to the file. SPOOL OUT stops the writing of output and
sends the output file to the printer.
Adding Comments to a Script File
Having comments in the script file improves the readability and understandability of the
code. You can enter comments in SQL*Plus using the
REMARKS (abbreviated REM) command.
Lines in the script file beginning with the keyword
REM are comments and are not executed.
You can also enter a comment between
/* and */. Comments can also be entered following
-- (double hyphen), all characters following -- in the line are treated as comment by Oracle.
While executing a script file with comments, the remarks entered using the
REMARKS com-
mand are not displayed on the screen, but the comments within
/* and */ are displayed on
the screen with the prefix
DOC> when there is more than one line between /* and */. You
can turn this off by using
SET DOCUMENT OFF.
This section provided an overview of SQL*Plus, the tool you will be using to enter and
execute SQL statements in Oracle Database 11g. In the next sections, I will discuss some of
the Oracle 11g SQL fundamentals before showing you how to write your first SQL query (a
SELECT statement).
Oracle Datatypes
The basic structure of data storage in the Oracle Database 11g is a table. A table can be
considered as a spreadsheet with columns and rows. Data is stored in the table as rows.
Each column in the table has storage characteristics such as the type of data contained in
EXERCISE 1.1 (continued)
95127c01.indd 15 2/18/09 6:37:07 AM