Vous êtes sur la page 1sur 20

Basic Orders

Introduction to SQL*Plus

Introduction to SQL*Plus

Preview
Editing orders

Files manipulation
Environment personalization

Formatting commands
Creating reports

Introduction to SQL*Plus

Editing commands
Buffer in SQL*Plus:

Introduction to SQL*Plus

Editing commands
Buffer in SQL*Plus:
Open Notepad to edit easily the latest SQL command.
ED[IT]

Block your environment until you close it.


afiedt.buf cant containt SQL*Plus environment orders.

For SQL*Plus environment orders, use an SQL script.

Introduction to SQL*Plus

Editing commands
Command list (non-exhaustive)
A[PPEND] text

C[HANGE] / old / new


CL[EAR] BUFF[ER]
CL[EAR] SCR[EEN]

DEL
DEL n

DEL m n

Introduction to SQL*Plus

Editing commands
Command list (non-exhaustive)
I[NPUT]

I[NPUT] text
L[IST]
L[IST] n

L[IST] m n
R[UN]

n
n text
0 text

Introduction to SQL*Plus

Editing commands
Example: Using LIST, n and APPEND
SQL> LIST
1 SELECT last_name
2* FROM employees
SQL> 1
1* SELECT last_name
SQL> A , job_id
1* SELECT last_name, job_id
SQL> L
1 SELECT last_name, job_id
2* FROM employees

Introduction to SQL*Plus

Editing commands
Example: Using CHANGE
SQL> L
1 SELECT * FROM employees
SQL> c/employees/departments
1* SELECT * FROM departments
SQL> L
1 SELECT * FROM departments

Introduction to SQL*Plus

Files manipulation
Command list (non-exhaustive)
SAV[E] filename[.ext] [RE[PLACE]]|[APP[END]]

GET filename[.ext]
STA[RT] filename[.ext]
@ filename[.ext]

ED[IT] [filename[.ext]]
SPO[OL] filename[.ext] [OFF|OUT]

EXIT

Introduction to SQL*Plus

Environment personalization
Some commands:
Use SET to control the current session
SET system_variable value

Verify your configuration with SHOW


SQL> SET ECHO ON
SQL> SHOW ECHO
echo ON

Introduction to SQL*Plus

Environment personalization
Some SET variables:
ARRAYSIZE {15 | n}
FEEDBACK {6 | n | OFF | ON}
HEADING {OFF | ON}
LONG {80 | n | ON | text}
LINESIZE {80 | n}
PAGESIZE {14 | n}
SQL> SET HEADING OFF
SQL> SHOW HEADING
heading OFF

Introduction to SQL*Plus

Formatting commands
Some commands:
COL[UMN] [column option]
TTITLE [text | OFF | ON]
BTITLE [text | OFF | ON]
BREAK [ON report_element]

Introduction to SQL*Plus

Formatting commands
The COLUMN command
To control the column display
COL[UMN] [{column | alias} [option]]

CLE[AR]: Removes all formatting options on the column


HEA[DING] text: Change the column heading

FOR[MAT] format: Modify the column display using


formatting options
NOPRINT | PRINT: Displays or not the column
NULL: Replaces NULL values

Introduction to SQL*Plus

Formatting commands
The COLUMN command
Create a column heading:
COLUMN last_name HEADING 'Employee|Name'
COLUMN salary JUSTIFY LEFT FORMAT $99,990.00
COLUMN manager FORMAT 999999999 NULL 'No manager'

Display current configuration for the LAST_NAME column:


COLUMN last_name

Remove the column configuration:


COLUMN last_name CLEAR

SELECT Statement

Formatting commands
COLUMN format models
Element

Description

Example

Result

Represents a number

999999

1234

Adds 0

099999

001234

Dollar currency

$9999

$1234

Locale currency

L9999

L1234

Decimal position

9999.99

1234.00

Thousands separator

9,999

1,234

Introduction to SQL*Plus

Formatting commands
The BREAK command
Avoid duplicate values on display
BREAK ON job_id

Introduction to SQL*Plus

Formatting commands
The TTILE and BTITLE commands
Displays pages headers and footers
TTI[TLE] [text | OFF | ON]

Configure reports headers


TTITLE 'Salary|Report'

Configure reports footers


BTITLE 'Confidential'

Introduction to SQL*Plus

Creating reports
Create a script file (.sql) to generate a report
1. Create and test your SQL statement.

2. Save your statement in a script file (.sql).


3. Edit your file in a text editor (Notepad).
4. Add formatting commands before the statement.

5. Verify the SQL terminator at the end of the statement (;).


6. Remove formatting commands after the statement.

7. Save your file.


8. Load and execute your file.

Introduction to SQL*Plus

Creating reports
Example output

Introduction to SQL*Plus

Part 2 Summary

SQL*Plus
commands

Format the
display

Edit the buffer

Create
formatted
reports