Non-SQL2 Features of Oracle 7.3.2
Here are some of the ways in which the class's Oracle implementation
differs from the SQL2 standard described in the text.
Please share with me and the class any differences, both additions and
missing features, that you find.
Contents
- Basic SQL Features
- Indexes
- Types
- Constraints
- Embedded SQL
Basic SQL Features
Indexes
-
In Oracle, you can get an index by the command:
CREATE INDEX <IndexName> ON <RelName>(<Attribute List>);
If the attribute list contains more than one attribute, then the index
requires values for all the listed attributes to find a tuple.
That situation might be helpful if the attributes together form a key,
for example.
An illustration of the CREATE INDEX command is
CREATE INDEX DrinkerInd ON Drinkers(name);
CREATE INDEX BarInd ON Bars(name);
which creates two indexes, one on the attribute name of
relation Drinkers and the other on the attribute name
of relation Bars.
-
To get rid of an index, you can say
DROP INDEX
followed by the
name of the index.
Notice that each index must have a name, even though we only refer to
the name if we want to drop the index.
-
On the Stanford Oracle installation, there are two disks, one for data
the other for indexes.
Every time you create an index, either explicitly with CREATE
INDEX or inplicitly with a PRIMARY KEY or UNIQUE
declaration, you should (on the Stanford system) follow the declaration
by TABLESPACE csindx.
In addition, if you are implicitly creating the index, you need the
phrase USING INDEX before TABLESPACE csindx.
For example:
CREATE INDEX DrinkerInd ON Drinkers(name)
TABLESPACE csindx;
or
CREATE TABLE Foo (
a INT PRIMARY KEY USING INDEX TABLESPACE csindx,
b CHAR(20)
);
Data Types
- Bit type is not supported.
- Oracle supports the DATE type for attributes.
However, the format of dates is not according to the SQL2 standard.
In fact, the stored format of dates is installation-dependent, and our
system uses the format 'dd-mon-yy'.
That is, two digits of day, a hyphen, a 3-character month abbreviation
(e.g., nov or apr), another hyphen, and a two-digit
year (yes, folks; we've got the ``year-2000 problem'').
Character strings in the proper format can be stored in date-valued
attributes or compared with dates.
For example:
CREATE TABLE Days(d DATE);
INSERT INTO Days VALUES('06-may-97');
SELECT d FROM Days WHERE d > '01-jan-90';
We can also convert other reasonable formats into dates with the
Oracle/SQL TO_DATE function.
This function takes a character string in any format and another string
that ``decodes'' the first, using the same convention as
for date masks described in the
material on the loader (y or Y begins a year field, etc.).
For example:
INSERT INTO Days VALUES(TO_DATE('1997/05/06', 'yyyy/mm/dd'));
- There is no analog of the TIME SQL2 type.
However, it is possible to use a (nondefault) format for dates that
includes hours, minutes, and seconds, so a date could play the role of a
time.
See Kristian Widjaja's guide to dates and
times for more details.
- Types in PL/SQL are tricky.
First, you cannot parametrize certain SQL types like CHAR(50),
although either
CHAR or VARCHAR(50) are OK.
However, comparisons between PL/SQL variables and data in your database
may not go the way you expect.
To be safe, declare the type of a PL/SQL variable that will be compared
with data from your database with the %TYPE attribute as
described in the
PL/SQL Guide.
Constraints
Embedded SQL
- The use of EXEC SQL BEGIN/END DECLARE SECTION is voluntary in
Oracle's SQL embedded in C.
However, if you embed SQL in C++, the declare-section markers are
required.
- Oracle doesn't allow FROM after FETCH in a
cursor-fetch statement.
There are also a number of problems that come not from Oracle's version
of embedded SQL per se, but that are a function of how their system
structure relates to the way people have set up their own environments.
Here are some of the most common problems we've seen:
- You need to use the Oracle-provided makefile, which we've edited
appropriately to reflect the details of the unix file structure.
This makefile includes definitions in a large Oracle-provided file of
definitions for terms like CFLAGS that the makefile needs.
Please follow the directions and use the class makefile, changing it
only by adding your .pc file and using your account name rather than
SCOTT/TIGER.
- You need to use the ``standard'' C compiler, in
/usr/pubsw/bin/cc.
We've found some people who have set their path to use the compiler in
/usr/ucb/cc, and this compiler can't handle the Oracle .c
files.
Try using the full path name for the compiler if you are having
trouble.
- If you don't have ``dot'' in your path, then you will have trouble
executing the files you create.
You can execute file foo by saying ./foo.
Stuart Miyasato does not recommend adding dot to your path for security
reasons.