USTHB – Computer Science Faculty 2024-2025
Module DB- L2 ISIL A
TP No1: The SQL Command Editor
SQLPlus or Run SQL Command Line are SQL command editors for the Oracle DBMS. These
editors allow users to connect to an Oracle database to execute SQL commands or PL/SQL
procedures. PL/SQL procedures will not be covered in this lab.
Types of Commands in SQLPlus
SQLPlus accepts three types of commands:
SQLPlus Commands: Internal commands of the SQLPlus editor, mainly used for
configuration. These commands do not manipulate database data. We will test these
commands in this lab.
SQL Commands: The query language used to retrieve and manipulate database data.
PL/SQL Commands: Oracle's procedural language, which integrates SQL queries with
procedural constructs (such as variables, loops, control structures, etc.).
Important Instruction
Download the files "TPOracleScript.sql" and "donnees.txt" from the website:
http://perso.usthb.dz/~nbouziane/TPBDD/. These two files will be used in all labs.
Entering SQL Commands
Once the SQL> prompt is displayed, you can start entering SQL commands.
Do not leave an empty line in SQLPlus for the same SQL statement.
SQLPlus is not case-sensitive for commands (e.g., SELECT and select are equivalent).
SQLPlus is case-sensitive for string values. Example: 'example' is different from
'EXAMPLE'.
SQL statements can be spread across multiple lines for better readability.
These statements are stored in a buffer, and the lines are numbered.
To execute a SQL statement:
o End the line with a semicolon (;).
o Press Enter to execute the command.
After executing a SQL command, SQLPlus will display the result.
USTHB – Computer Science Faculty 2024-2025
Module DB- L2 ISIL A
Task 1: Launching the SQLPlus Editor
1. The SQLPlus editor can be found on the Windows desktop or in the "Programs" menu.
This lab uses SQLPlus, which functions the same as Run SQL Command Line, except
that the CONNECT instruction must be entered at startup in the latter.
2. Connect to Oracle using the system user with the password (pre-installed with Oracle).
3. The SQL > prompt indicates that you are connected to Oracle.
4. Any commands entered from this point onward are SQL commands for the DBMS.
5. Write and save all SQL instructions in a file with the ".sql" extension using Notepad++
(or any other software), and select SQL as the language from the "Language" menu.
Task 2: Using SQLPlus Commands
1. Test the SQLPlus commands listed in the table below.
2. These commands can be abbreviated. For example, CONNECT can be written as CONN.
3. Here is the translated table:
Command Description
SQLPlus
CONNECT Establishes a new connection. Syntax: CONN[ECT]
"username" "password"
DISCONNECT Disconnects from the database. Syntax: DISC[ONNECT]
QUIT Exits the SQLPlus tool and disconnects Syntax: QUIT
from the database.
RUN The RUN command or « / » displays the Syntax: R[UN] or /
content of the buffer and executes the
stored instruction.
EDIT Opens a file. Syntax: ED[IT]
filename[.extension]
SHOW USER Displays the currently connected user. Syntax: SHO[W] USER
Task 3: Executing a SQL Script in SQLPlus
A SQL script is a file that contains SQL commands.
o Example: The script file used in this lab is "TPOracleScript.sql".
To execute a script in SQLPlus:
o Ensure that the file path does not contain spaces.
o Enter : SQL> @path_to_script(with extension .sql)
To interrupt a running SQL command, press Ctrl+C or Del.
USTHB – Computer Science Faculty 2024-2025
Module DB- L2 ISIL A
1. Create a directory TPBDD on the C: drive.
2. Save the files TPOracleScript.sql and donnees.txt in the TPBDD directory.
3. Open the SQLPlus editor.
4. Enter the username: system and password
5. Execute the script "TPOracleScript.sql".
Task 4: Saving the Work Session
To save all user-entered commands and Oracle responses to a file, use the SPOOL
command. The file will be created by the following command (it does not exist
beforehand):
SPOOL path\to\save_directory\filename_without_extension
1. Start the following spool:
SPOOL c:/TPBDD/sauvegarde
This will create a file named "sauvegarde.LST".
2. Stop spool and close the file using:
SPOOL OFF
3. Analyze the content of the file sauvegarde.LST.
4. What does the file sauvegarde.LST contain?
5. Restart the SPOOL.
6. Re-execute the script "TPOracleScript.sql".
7. Stop the backup
8. Open the file sauvegarde.LST and analyze its contents.
9. What does the file sauvegarde.LST contain?