2.8. Script Output

You redirect SQL*Plus output with a SPOOL command. You choose to “spool to a file” at the beginning of the script. You “end the spooling process” at the end of the script. Some scripts can be lengthy—they drop and recreate 50 tables and include many insert statements for test data. These types of scripts often spool output for verification purposes.

					-- filename MY_STUDENTS.sql
spool my_students
DROP TABLE students;
CREATE TABLE students
(student_id    VARCHAR2(10),
 student_name  VARCHAR2(30),
 college_major VARCHAR2(15),
 status        VARCHAR2(20) ) TABLESPACE student_data;

INSERT INTO students VALUES
 ('A123','John','Math','Degree');

INSERT INTO students VALUES
 ('A124','Mary','Biology','Degree');
COMMIT;
spool off

The output from the ...

Get Programming Oracle® Triggers and Stored Procedures, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.