At the SQL*Plus prompt, use LIST to inspect the last SQL statement, SHOW to inspect client settings, and SPOOL to capture displayed output in a file. If you only want to see what you typed, do not enter a slash: unlike LIST, a slash executes the statement again. The distinction matters even after the first execution has finished.
Before you start
These examples assume the SQL*Plus 19c command-line client on Linux x86-64 and an ordinary account already connected to the intended Oracle Database 19c pluggable database (PDB). Use a fresh session with no pending work. The only query in the exercise reads a literal from DUAL; you do not need a sample schema or an administrative login. For the file exercise, use a private working directory where you may create files. The examples are documented but have not been tested here.
To decide which package you need, see the Oracle client download guide. If the executable is missing, start with installing Instant Client and SQL*Plus. Oracle lists the client by platform on its Linux x86-64 download page. If a support ticket asks for a version, distinguish the local program from the server: see how to check the client and connected database versions separately.
1. Check the session before labeling it
SHOW CON_NAME
SHOW LINESIZE
SHOW PAGESIZE
SHOW SQLPROMPT
Compare the container name with the PDB you intended to use. If it differs, stop and reconnect using your approved procedure. Record the three client settings if you intend to restore them later. These are SQL*Plus commands: enter each on its own line at the client prompt, without a SQL statement terminator. See Oracle’s SHOW command reference.
Change the prompt without changing the connection
SET SQLPROMPT 'report> '
The next prompt should use your label. The quoted space separates the label from what you type. A prompt labeled report> does not make a session read-only, select a PDB, or establish who is logged in. Use the container check, not the prompt, when the target matters. If you use substitution variables in a prompt, they are evaluated when you set it; do not assume they are refreshed before each command. See SET SQLPROMPT.
2. Inspect a statement without executing it twice
SELECT 'review' AS report_label FROM dual;
LIST
The first line is SQL. With the normal semicolon terminator it runs immediately. The second line asks the client to show the statement text, not the result rows. SQL*Plus keeps the most recent SQL statement or PL/SQL block in its SQL buffer. Typing a client command such as SHOW LINESIZE does not replace the buffered query.
| Command | What happens to the buffered statement |
|---|---|
| LIST | Shows its lines. Does not execute it. |
| RUN | Lists it, then executes it. The listing is not a confirmation prompt. |
| / | Executes it without listing it first. |
For this read-only query, running it again requests the value again. For a statement that changes data, another execution is another attempt to make that change. Do not append a slash on a line after every semicolon. If you have lost track of what is in the buffer, inspect it with LIST before deciding whether to execute anything.
3. Separate object information from report formatting
DESCRIBE dual
Use DESCRIBE when the question is which columns an accessible table or view exposes and what their types are. It does not retrieve the rows. Conversely, the alias report_label in the example belongs to the query result: do not look for it in the description of DUAL.
SET LINESIZE 100
SET PAGESIZE 40
COLUMN report_label FORMAT A12
SELECT 'review' AS report_label FROM dual;
LINESIZE sets the output line width in characters. PAGESIZE sets lines per report page, not how many rows the database returns. A value of zero suppresses headings as well as page breaks. If a heading disappears, inspect this setting before rewriting the query.
The COLUMN format applies to the named result column: A12 gives the text a display width of 12 characters. Neither the stored data nor the SQL expression has changed. If the format seems to have no effect, compare its name with the alias in the actual select list. To remove just this definition, use COLUMN report_label CLEAR. CLEAR COLUMNS resets every column definition, including ones you did not create for this exercise.
4. Capture one result in a new file
Use a new filename in the private directory you selected. The example specifies CREATE deliberately: if you omit the file mode, SPOOL defaults to REPLACE and can overwrite an existing file. Do not spool credentials or production result sets into a practice report. See Oracle’s SPOOL syntax and compatibility limits.
SPOOL report-check.lst CREATE
SPOOL
Check the reported spooling status and destination before continuing. If the file already exists, choose another new name rather than switching to REPLACE. If the command is rejected, confirm that the directory is writable and that the SQL*Plus compatibility setting is not 9.2 or earlier, which disables the CREATE option.
SELECT 'review' AS report_label FROM dual;
SPOOL OFF
SPOOL
Verify that spooling has stopped, then open the new file in a text viewer and locate the value from the query. This is a capture of displayed output, not a database backup or an export of the underlying table. If headings or wrapping are wrong in the file, correct the display settings and capture the query to another new file.
5. Run a reviewed script by name
For a repeatable check, save the single read-only query above in a local text file named report-check.sql. Keep the statement terminator; leave out the displayed prompt, any copied result rows, and any trailing slash. Review the file before running it. At the client prompt, enter:
@report-check.sql
@ runs a script, as does START. For a relative filename the current working directory is searched first. This is different from executing the contents of the SQL buffer: if you edited the file and want the new contents, invoke the file by name again. When one local script calls another stored beside it, use @@ inside the calling script to resolve the nested filename relative to that script.
A script that changes client settings can leave them changed after it returns. Before reusing the session, clear the example’s column definition and restore the prompt, line width, and page size you recorded at the start. Check them with SHOW and confirm that spooling is off. That separates a successful report run from a session that is also ready for the next task.
