Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SQLPlus Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

1

Oracle SQLPLUS
(For 60-315, Fall 2023)
Some SQLPLUS Commands

1. Using Bitvise SSH Secure Shell to login to CS Systems


Note that if you do not have Bitvise ssh secure shell on your PC, you can download it
from http://www.putty.org/. Some instructions have also been provided in the
course announcement page on how to install Bitvise SSH or NoMachine for remotely
connecting to the CS servers (alpha.cs.uwindsor.ca, bravo.cs.uwindsor.ca,
charlie.cs.uwindsor.ca, or delta.cs.uwindsor.ca).

Note that:
1. you ought to have installed GlobalProtect VPN to be able to connect to
any of the CS servers through Bitvise SSH or NoMachine.
Information on How to Install or Update GlobalProtect VPN

• New University VPN Users: View the KBAs with instructions on how to install
the Global Protect VPN.
• Existing University VPN Users: Find Update the VPN per the KBA to see how
to remove the old portal networklogin.uwindsor.ca to the
new securelogin.uwindsor.ca.
• Should you require help with the VPN, please contact the IT Service Desk
by opening a ticket, calling 519-253-3000 ext. 4440 or selecting the chat icon in
the bottom right corner of uwindsor.ca/its or uwindsor.ca/itshelp.
2. You ought to have synchronized your UWindsor email password
with the Oracle Sqlplus password (i) every time you change your
UWindsor email password, (ii) first time you are logging
onto Sqlplus on cs servers, and (iii) any time you are working
on Sqlplus on our cs server and got locked out.
To synchronize, go to http://cs.uwindsor.ca/password. Then, follow the
appropriate buttons to synchronize.
The characters that can be used for an Oracle/UWindsor
password without enclosing it in double quotes are the same as
any normal Oracle identifier: only letters, numbers, and the
symbols #, _, and $ are acceptable, and the first character must
be a letter. If your password includes any other characters, the entire
2

password MUST be enclosed in double quotes (for an example strange


password, “*%22strange”) for the Oracle login.
3. Connect to any of the CS machines through either Bitvise SSH
(http://www.putty.org/) or Nomachine
(https://www.nomachine.com/download). These two software
programs can be downloaded from their websites. More
details on how to obtain them are provided below.

How To Connect to CS server

To connect to a CS server, do:

1. Launch the ssh secure shell


2. Click on Quick Connect
3. Enter Host Name eg: bravo.cs.uwindsor.ca
4. Enter User Name eg: smith
5. Port Number: 22 (default)
6. Authentication Method: <profile Setting> (default)
7. Then press ENTER
8. Enter Password eg: XXXXXX

When connected to the computer science system bravo.cs.uwindsor.ca, you can use
SQLPLUS Oracle’s interactive Interface to the database server. SQL statements can be
issued at the SQL> prompt and file containing SQL statements can be executed from
within SQLPLUS.

2. Oracle SQLPLUS
Oracle’s SQLPLUS program provides a convenient interactive environment with the
Oracle Database Server. The user may type the commands directly at the SQL> prompt
or have SQLPLUS execute commands residing in operating system files.

2.1 Entering and Exiting Oracle SQLPLUS

To enter the SQLPLUS environment, the sqlplus program should be executed (launched)
from Unix/Linus command line in one of the following two ways, where
<user id> is the oracle user identification and
<password> is the associated password:
• sqlplus <userid>
• sqlplus
The Oracle userid and password may be different from the userid and password to get
access to the operating system (with the current Oracle DBMS 11g, it is the same
password for both your server account and Oracle account).
3

If the sqlplus program is invoked with only <userid>, the program prompts the user for
the password; if it is invoked without any parameters, the program prompts for the
<userid> and <password>

To Exit the SQLPLUS environment, the exit or quit command must be entered at the
SQL> prompt.

SQL> quit

2.2 Executing Commands in SQLPLUS

Once the user is within the SQLPLUS environment, the system will usually display the
prompt SQL> and wait for the user commands. The user may enter three kinds of
commands:

• SQL statements, to access the database


• PL/SQL blocks, also to access the database
• SQLPLUS commands, for editing and storing SQL statements and PL/SQL
blocks, setting options, and formatting query results.

SQL statements can be entered at the SQL> prompt. A statement may be broken into
multiple lines. SQLPLUS displays a line number (starting at 2) after the user presses the
RETURN key to go to the next line. The SQL statement may be terminated in one of the
three ways:

• With a semicolon (;), indicating to SQLPLUS that it should execute the statement
immediately.
• With a slash (/) on a line by itself, also indicating to SQLPLUS that it should
execute the statement immediately.
• With a blank line, indicating to SQLPLUS that it should not do anything with the
statement. The statement is stored in a buffer and can be executed at a later stage

The following is a screen capture of an SQL statement executed in SQLPLUS from the
CEZEIFE ACCOUNT

SQL Statement:
SQL> select course_no AS course#, c_title "course title", c_credit " course credit"
2 from uw_courses;
4

Figure2.2

Figure 2.3
5

You can also enter PL/SQL anonymous blocks at the SQL> prompt for execution and
issue statements such as create function and create procedure at the SQL> prompt to
create PL/SQL stored objects.

The PL/SQL anonymous block is executed by typing the “run” command at the SQL>
prompt.

Besides SQL and PL/SQL, users can also enter SQLPLUS commands at the SQL>
prompt. These commands can manipulate SQL commands and PL/SQL blocks, format
and print query results, and set various options for SQLPLUS. SQLPLUS must be
entered in one line. If the command is long, it may be continued to the next line by typing
the hyphen symbol (-) at the end of the line before pressing the RETURN key. Here is an
example of an SQLPLUS command that formats a column of the SQL query.

SQL Statement
SQL> select course_no AS course#, c_title "course title", c_credit " course credit"
2 from uw_courses;

SQL> column c_credit format –


➢ 99.99 heading “Course Credit”
SQL> run
1 select course_no, c_title, c_credit
2 from uw_courses;

Figure 2.4

The column command formats a particular column in the current query (in this case the
6

column is formatted and given a different name for display purposes). SQLPLUS
commands need not be terminated with semicolon

The following are a few of the more commonly used SQLPLUS commands
• describe [desc] List the column definitions for a database table. The following is
an example of the describe command

Figure 2.5

Figure 2.6
7

• execute. Execute a single PL/SQL statement. The syntax is

SQL> execute statement

• help. Gets online help for SQLPLUS commands. For example,

SQL> help column

Will list the description of the column command. To get a list of all commands
use the following command:

SQL> help <command name>

• host. Execute a host operating system command without leaving SQLPLUS. For
example,

SQL> host ls * .sql


8

Will list all the files in the current directory with a .sql extension. The
exclamation key (!) may be used instead of the host command to achieve the same
effect.

Figure 2.7

• remark. Used for comments. Any line beginning with keyword remark or rem or
two hyphens (--) is treated as a comment and is ignored by SQLPLUS.

• Run. Executes the SQL statement present in the buffer. The run command works
the same as the slash command, except that it also displays the buffer contents
before executing the statement in the buffer.

• Set. Sets SQLPLUS system variables. Some of the more useful system variables
include

SQL> set pause on;


SQL> set autoCommit on;
SQL> set echo on;

Setting pause to on causes SQLPLUS to pause at the beginning of each page. The
user must press RETURN key to see the next page.

Setting autoCommit to on informs Oracle to commit any changes to the database


immediately after the SQL statement that has caused the changes, is executed.

Setting echo to on causes SQLPLUS to list each commands in a file when the file
is run with the start command. The names of other system variables, along with
explanations, can be obtained by using help on the set command.
9

Figure 2.8

3 Buffer Manipulation Commands


The most recent command that is entered on the SQL prompt is stored in the
SQLPLUS buffer. It is possible to access, change, append to, and save the contents of
the buffer. The SQLPLUS buffer editing commands are listed below. All the editing
commands (except for the list command) affect only one line, the current line. To
10

make a particular line the current line, simply list that line by typing the line number
the following SQLPLUS session illustrates some of the editing commands.

Figure 3.1
11

Figure 3.2
12

Table 3.1 SQLPLUS buffer editing commands.

Command Abbreviation Explanation

Append text A text Add text to the end of a line

Change /old/new C /old/new Change old to new in a line

Change /text C /text Delete text from a line

Clear buffer C buff Delete all lines

Del Delete a line

Get file Load contents of file named file


into buffer
Input I Add one or more lines

Input text I text Add a line consisting of text

List L List all lines in buffer

List n L n or n List one line and make it the current


line
List * L* List the current line

List last L last List the last line

List m n Lmn List lines m through n

Save file Sav file Save contents of buffer to file


named file.

You might also like