Oracle/SQL Tutorial: Starting A Session
Oracle/SQL Tutorial: Starting A Session
The Oracle Relational Database Management System (RDBMS) employs the Structured
Query Language (SQL) to perform queries on databases. This tutorial focuses on the basics of
using SQLPlus in CAEN’s UNIX operating system environments.
SQLPlus is Oracle’s SQL interpreter. With it, you can perform queries, manipulate data, and execute
simple report formatting calls. Its simplicity makes it a good application to start off with when
learning SQL.
In order to use Oracle, you will need to (1) have a CAEN Oracle account, and (2) set up your
environment so that the Oracle applications (i.e., SQLPlus) can find the Oracle home directory and
server. To obtain an Oracle account, use the Contact CAEN feature on CAEN’s website to request
one.
Starting a Session
Once you have a personal or class account, execute the following command from the UNIX
command prompt to set up your environment for Oracle usage:
source /usr/caen/oracle/local/muscle
This adds a directory to your PATH variable and sets other relevant environment variables. To
invoke SQLPlus, simply type sqlplus at the UNIX shell prompt. The introduction banner will scroll
by and you will be prompted for your user name and password. After logging in, the SQL> prompt
appears.
You can change your password from the UNIX command prompt by using the command
opasswd. Do not use non-alphanumeric characters in your password, as Oracle treats a number of
them in a special manner.
If you would like to change it through SQLPlus, run sqlplus and enter the command:
/* Help function */
help describe
/* Tabs — view of user-owned tables */
select * from tabs;
set pagesize 900
/* Table creation */
help create table
create table pup (
pupno number(2) not null,
name varchar2(10),
knlno number(2)
);
/* Finding the description of a table */
desc pup
create table x (
val date
);
select table_name from tabs;
/* Deleting a table */
drop table x;
/* Accessible tables — also see all_tables */
desc accessible_tables
select table_name from accessible_tables;
/* Keep record of your session */
spool sqltutorial
/* Creating a copy of a table from another schema */
create table kennel as select * from sqltut.kennel;
desc kennel
/* Creating a sequence */
create sequence pup_seq start with 10 increment by 1;
/* Creating a view */
create view puppynames as (
select name from pup
);
desc puppynames
/* Table DUAL — the dummy table */
desc dual
select user, sysdate, pup_seq.nextval from dual;
/* Insertion and sequence usage */
insert into pup (pupno, name, knlno)
values (pup_seq.currval, ‘fido’, 2);
insert into pup
values (pup_seq.nextval, ‘spot’, 3);
select * from pup;
/* Insertion as copy from another table */
insert into pup select * from sqltut.pup;
select * from pup;
/* Committing changes — don’t forget rollback */
commit;
/* Simple queries */
select * from pup where name = ‘spot’;
select * from pup where name in (‘spot’, ‘fido’);
select * from pup where pupno > 3;
select * from pup where pupno between 2 and 4;
select * from pup where name like ‘sp%’;
Additional Help
On-line manuals can be found at the CAEN web site:
http://www.engin.umich.edu/caen/wls/software/oracle/
andOracle’s:
http://www.oracle.com/