Professional Documents
Culture Documents
AIM: - To develop familiarity with basic SQL information and query commands.
TASKS: These exercises are based on the Pine Valley Furniture Company database. The sample
database has been loaded into an Oracle SQL database hosted at Deakin. All the table names have
been prefaced with “L_” to distinguish them from any other tables you may make later.
PuTTY is also available online for download from Deakin Software Library if
you would like to have it setup on your own PC:
http://software.deakin.edu.au/?s=PuTTY
Page 1
Apple/Mac Users:
Mac users should use the terminal application. On Deakin MacOsX machines this is at
applications → utilities → terminal.
Then the system will ask for your password. Type in your central university password and
press Enter.
Now you should be displayed with the following menu:
After logging in select the menu entry “SQLPlus to SSID.” You should see:
You will need to re-enter your password. NOTE: Oracle does not move the cursor as you
type the password. But it is listening! Just type the password and press Enter. This process
should be trouble free, however if your password contains anything other than upper and
lower case letters and numbers it may cause problems.
• If you have trouble with your password, change it to one which does not contain
anything other than upper and lower case letters and numbers at
https://www.deakin.edu.au/password/change/ after you change the password, it will
take some minutes to update.
You should get a response similar to the following (may not be exact):
Note that the table names may differ slightly between students.
• You’ve probably worked out by now that there’s a lot of repetitive typing in this level of
database querying. You might like to keep a copy of a text editor (such as notepad)
open to copy and paste commands you use a lot.
Similarly, one can describe individual tables. This can be very useful if you’ve forgotten
exactly what you defined in the first place, or where you’ve forgotten the type of an
attribute (or similar lapse in memory).
Let’s describe the table L_customer. This is done using the command
DESC L_customer;
Page 3
Task 3 – Entering and editing SQL commands
We need to not only describe our database, but we also need to submit commands to either
change the databases content or structure, or to execute queries (questions). To do this we
need to enter SQL queries.
You’ll notice the output looks messy as database rows are wrapped around into the following
line. To solve this issue set the line width to 132 characters (default is 80):
set linesize 132;
Notice that this time the information is sorted by customer_name (the second column). The
same effect can be obtained by using the phrase order by customer_name. Try it and check.
You are now ready to try out some SQL queries yourself. If you don’t finish these in your lab
session, it is up to you to finish them before next time. Initially we will concentrate on typing
queries and receiving results. Later you will be expected to formulate the queries yourself. In
this task we will concentrate on one table – customer.
Page 4
Select states recorded (note duplicates in resulting table)
SELECT customer_state
FROM L_customer;
At this point, you might have noticed that I’m using a bit of a convention on how to write an
SQL query:
SELECT <columns>
FROM <tables>
Writing the queries this way, helps to understand what you are doing.
The output from these queries is more than a little messy, but remember that you are
working at the real database coalface – there are other programs and output interfaces
which make the output look better. Most serious applications (DSO, Star, bank systems) and
some not so serious (Facebook, YouTube) have SQL behind them. We can do some basic
preparing of the data using SQL though:
It is possible to force the output so that it is sorted by particular column(s) using the
ORDER BY clause.
Ordering rows for a resulting table (alternative – ascending is the default; ‘1’ says column 1
of the resulting table)
Page 5