You are on page 1of 16

Introduction SQL*Plus

Materi 3
MK. Manajemen dan Administrasi Basisdata
Dosen : Roni Salambue, M.Si
Objectives
• Explain about SQL Plus Architecture
• Learn about SQL Plus commands and their uses
Outline
• Overview
• Architecture
• Starting SQL Plus
• Exiting SQL Plus
• SQL*Plus’s Relation to SQL, PL/SQL, and the Oracle Database
SQL*Plus Overview
• SQL*Plus is an interactive and batch query tool that is installed with
every Oracle Database installation.
• It has a command-line user interface.
• SQL*Plus has its own commands and environment, and it provides
access to the Oracle Database.
• It enables you to enter and execute SQL, PL/SQL, SQL*Plus and
operating system commands to perform the following:
• Format, perform calculations on, store, and print from query results
• Examine table and object definitions
• Develop and run batch scripts
• Perform database administration
SQL*Plus Command-line Architecture
• SQL*Plus command-line uses a two-tier model comprising:
• Client (command-line user interface).
• Database (Oracle Database).
• The two tiers may be on the same machine.
• SQL*Plus Client The command-line user interface is the character-
based terminal implementation.
• Oracle Database Oracle Database Net components provide
communication between the SQL*Plus Client and Oracle Database.
Starting SQL*Plus Command-line - Connecting
to a Default Database
• Open a UNIX or a Windows terminal and enter the SQL*Plus command:
sqlplus

• When prompted, enter your Oracle Database username and password.


• Alternatively, enter the SQL*Plus command in the form:
sqlplus username

• You are prompted to enter your password.


Starting SQL*Plus Command-line - Connecting
to a Different Database
• From an existing command-line session, enter a CONNECT command
in the form:
SQL> connect username@connect_identifier
• You are prompted to enter your password
Exiting SQL*Plus
• To exit SQL*Plus command-line, enter EXIT.
SQL> exit;
SQL*Plus’s Relation to SQL, PL/SQL, and the
Oracle Database
• SQL*Plus is often used in conjunction
with two other products, both of
which have the letters “SQL” in their
names.
• The first is SQL itself. Without a
doubt, the most common use of
SQL*Plus is to submit SQL
statements to the database for
execution.
• The second product is
Oracle’s PL/SQL procedural
language.
SQL*Plus’s Relation to SQL, PL/SQL, and the
Oracle Database
Product Description
SQL is an ANSI and ISO standard language used
to insert, delete, update, and retrieve data from
SQL
relational databases. SQL is also used to manage
relational databases.
PL/SQL is a proprietary procedural language
developed by Oracle as an extension to SQL, for
PL/SQL use in coding business rules and other procedural
logic at the database level. Like SQL, PL/SQL
executes inside the database engine.

SQL*Plus is an Oracle-developed tool that allows


SQL*Plus you to interactively enter and execute SQL
commands and PL/SQL blocks.
Listing a Table Definition
• To describe a database object, for example, column details for
EMP_DETAILS_VIEW, enter a DESCRIBE command like:
DESCRIBE EMP_DETAILS_VIEW
DESC EMP_DETAILS_VIEW
Writing Scripts with a System Editor
• Your operating system may have one or more text editors that you
can use to write scripts.
• You can run your operating system's default text editor without
leaving the SQL*Plus command-line by entering the EDIT command.
• You can use the SQL*Plus DEFINE command to define the variable,
_EDITOR, to hold the name of your preferred text editor.
• For example, to define the editor used by EDIT to be gedit, enter the
following command:
SQL> DEFINE _EDITOR = gedit
SQL> ed
Sending Results to a File
• To store the results of a query in a • SQL> SPOOL file_name
file—and still display them on the • SQL> SPOOL
screen—enter the SPOOL lesson_at_week2.txt
command in the following form:
• SQL> SPOOL off
• SQL*Plus stores all information
displayed on the screen after you • SQL> gedit
enter the SPOOL command in the lesson_at_week2.txt
file you specify.
• If end of session, screen—enter the
command in the following form
• To view the files, the command is:
Format Column
• Format column
COLUMN column_name HEADING column_heading
• Example
COLUMN LAST_NAME HEADING 'LAST NAME'
COLUMN SALARY HEADING 'MONTHLY SALARY'
COLUMN COMMISSION_PCT HEADING COMMISSION
SELECT LAST_NAME, SALARY, COMMISSION_PCT
FROM EMP_DETAILS_VIEW WHERE JOB_ID='SA_MAN';
Format Column
• Changing the Default Display
• The COLUMN command identifies the column you want to format and the
model you want to use, as shown:
COLUMN column_name FORMAT model
• Example:
COLUMN first_name FORMAT a10
• How to make table look fit on the screen?
• Use the following command:
SET LINESIZE value
• Example:
SET LINESIZE 300
Thank you

You might also like