Topics
To run the interactive sql client, sqlplus, you will first have to
execute the commands in
To run the interactive sql client, sqlplus, you will first have to
execute the commands in
You can change your ORACLE password using the SQL grant command:
grant connect to <user id> identified
by <password>;
For example, grant connect to finin
identified by ragnarok;
The semi-colon at the end of the command is required.
SQL> commit
Discard all changes made since the last commit:
SQL> rollback
EXAMPLE:
create table myrelation
insert into myrelation values
insert into myrelation values
insert into myrelation values
select *
drop table myrelation;
spool out
SQL> save working.sql app;
NAME ITE AMOUNT
---------- --- ----------
Box i4 12.93
Box i8 98.23
Phone i3 54.23
Table i2 23.12
Table i6 54.98
Chair i1 23.84
Chair i5 43.98
Chair i9 23.12
Chair i7 23.45
SQL> break on name skip 1
SQL> select name, item#, amount
2 from inventory
3 order by name;
NAME ITE AMOUNT
---------- --- ----------
Box i4 12.93
i8 98.23
Phone i3 54.23
Table i2 23.12
i6 54.98
Chair i1 23.84
i5 43.98
i9 23.12
i7 23.45
Example: one line title
Company Sale Report
NAME ITE AMOUNT
---------- --- ----------
Box i4 12.93
i8 98.23
. . .
SQL> select name, item#, amount
2 from inventory
3 order by name;
Company Sale Report
===========================
Personal Report Sales Department
NAME ITE AMOUNT
---------- --- ----------
Box i4 12.93
i8 98.23
source /opt/bin/oracle_cshrc
sqlplus
or you could add the contents of this file to your .cshrc:
Access ORACLE DBMS on CS
Currently the client and server are only installed on
everest.cs.umbc.edu so you will have to log into that machine
to use the client.
ORACLE Login Procedures
ORACLE can only be accessed in your cs account. When you log
into the account the first time, you need to set up the ORACLE working
environment and change its password following the steps.
source /opt/bin/oracle_cshrc
sqlplus
or you could add the contents of this file to your .cshrc:
Invoking SQLPLUS
To enter the ad hoc query system, invoke the sqlplus command.
dbs1[2]% sqlplus
SQL*Plus: Release 3.3.2.0.0 - Production on Thu Nov 7 15:23:29 1996
Copyright (c) Oracle Corporation 1979, 1994. All rights reserved.
Enter user-name: finin
Enter password:
Connected to: Oracle7 Server Release 7.3.2.1.0 - Production Release
With IRIX Enhancements, PL/SQL Release 2.3.2.0.0 - Production
SQL> help;
HELP
HELP [topic] | help
HELP displays information on the commands and conventions of SQL*Plus,
SQL, and PL/SQL. Type "help", a space, all or part of any topic, and
then press Enter.
Typing only part of a topic (for example, HELP SE) will cause all help
topics that match the string (SE) to be displayed on your screen in
alphabetical order (for example, HELP SE will retrieve help on the
SELECT statement, the SET command, and the Set Operators--in that order).
ENTER THIS... TO DISPLAY THIS...
--------------------------------------------------------------
help commands a list of SQL*Plus, SQL, and PL/SQL commands
help comm information on commands, comments, and commit
help help this screen
SQL> exit;
Disconnected from Oracle7 Server Release 7.3.2.1.0 - Production Release
With IRIX Enhancements
PL/SQL Release 2.3.2.0.0 - Production
dbs1[3]%
Exit From SQLPLUS
Type Exit while inside SQLPLUS followed by the
Enter key.
Documentation and help
To get help from the SQL prompt, you can simply type `help something',
where `something' is a command (e.g. `help select;'), a function
(e.g. `help to_char;'), or a datatype (e.g. `help char;'). This is
the fastest and easiest way to get help with commands. There is
another, more comprehensive documentation program (oradocm) which has
not yet been installed.
Protect Your Work from Mistakes
You should execute the commit command before you change
your database. When you are satisfied with your work, you could
save it in the database permanently by executing the commit
command, or you could discard all changes you made since the last
commit command by typing rollback command.
Save all changes in the database:
Other Useful SQL Commands
select *
from system.tab;
SQL> describe <relation name>
SQL> describe student
SQL> help <the SQL command>
You could also find out all commands by entering:
SQL> help menu
Prepare SQL Statements as Text Files
You could prepare all your SQL commands, such as creation of relations
and queries, into a text file and execute the SQL commands in this
file when you are in SQLPLUS.
As the file, working.sql, is kept in the UNIX account,
you should down load it to your PC from the UNIX account and
then print it from your printer or incorporate it into your
document.
cat myoutput.lst
(mykey char(4), name char(30), address char(50));
('1020', 'John Smit', '1 Main Street');
('1030', 'Linda Jade', '1 Main Street');
('1040', 'Tom Dube', '1 Main Street');
from myrelation;
myquery.sql
Once the file is transformed into UNIX, you can run the SQL
statements after you log into SQLPLUSi. Assume that you name
the SQL file as myquery.sql.
SQL> start <your sql file name>
EXAMPLE:
SQL> start myquery.sql
SQL> edit <your SQL file name>
EXAMPLE:
SQL> edit myquery.sql
After errors are fixed, you may repeat the above steps again.
SQL> save <file name>
You last query:
SQL> select *
To save it into a file:
from student;
SQL> save working.sql;
To append a tested query into the same file:
SQL> select *
from class;
Query Results Output
SQL> spool <your file name>
EXAMPLE:
SQL> spool myoutput.out
All database activities after this command are written into this file.
SQL> spool off (stop spooling)
Once you have the output file, you could print out the file use
the lpr command of the computer system after you exist
from SQLPLUS.
SQL> spool out (stop spooling & send the file
directly to a printer)
Simple Formatting Query Results
SQL> column
Example:
SQL> column desc heading description
Two line heading example:
SQL> column Emp# heading 'Employee|Number'
SQL> set underline =
set the underline character to the equal character.
SQL> column salary format $999,999
SQL> column name format A8
If a name is longer than 8 characters, the remaining is displayed
at the second line (or several lines)
SQL> select name, item#, amount
2 from inventory
3 order by name;
SQL> ttitle center 'Company Sale Report' skip 1
SQL> select name, item#, amount
2 from inventory
3 order by name;
Example: multiple line title
SQL> ttitle center 'Company Sale Report' skip 1 -
> center ================================ skip 1 -
> left 'Personal Report' right 'Sales Department' skip 2
SQL> ttitle center 'Company Sale Report' skip 1 -
SQL> set pagesize 60
SQL> clear break
SQL> clear column
SQL> ttitle off (may be turn on by using the 'on'switch)