background image
<< ROLLBACK to the Savepoint | Creating and Using Tables >>
<< ROLLBACK to the Savepoint | Creating and Using Tables >>

Creating and Using Database Objects

Creating and Using Database Objects 3-1
3
Creating and Using Database Objects
In this chapter, you will create and use the types of database objects that were
discussed in
"Querying and Manipulating Data"
.
Note that the statements
CREATE TABLE
,
ALTER TABLE
,
DROP TABLE
, and so on,
use an implicit commit, and cannot be rolled back.
This chapter contains the following sections:
Using Data Types
on page 3-1
Creating and Using Tables
on page 3-2
Using Views
on page 3-21
Using Sequences
on page 3-25
Using Synonyms
on page 3-28
Using Data Types
Data types associate a set of properties with values so you can use these values in the
database. Depending on the data type, Oracle Database can perform different kinds of
operations on the information in the database. For example, it is possible to calculate a
sum of numeric values but not characters.
Oracle Database supports many kinds of data types, including the most common
VARCHAR2(length)
,
NUMBER(precision, scale)
,
DATE
, and also
CHAR(length)
,
CLOB
,
TIMESTAMP
, and others. As you create a table, you must
specify data types for each of its columns and (optionally) indicate the longest value
that can be placed in the column.
Some of the data types and their properties you will use here include the following:
The
VARCHAR2
stores variable-length character literals, and is the most efficient
option for storing character data. When creating a
VARCHAR2
column in a table,
you must specify the maximum number of characters in a column, which is a
length between
1
and
4,000
. In the
employees
table, the
first_name
column
has a
VARCHAR(20)
data type and the
LAST_NAME
column has a
VARCHAR2(25)
data type.
An option to the
VARCHAR2
data type,
NVARCHAR2
stores Unicode variable-length
character literals.
The
CHAR
data type stores fixed-length character literals; it uses blanks to pad the
value to the specified string length, which is between
1
and
2,000
.
An option to the
CHAR2
data type,
NCHAR
stores Unicode fixed-length character
literals.