Oracle 10g Free Training : Tables
In this tutorial you will learn about Tables, Summary of Oracle Built-In Datatypes, Types of tables, Restrictions to consider when Creating Tables along with logical databse limits.
Tables
Tables are the basic unit of data storage in an Oracle Database. A table consists of columns and rows. Data is stored in these rows and columns. A table definition required a table name and the description of the columns that would be contained in this table. Rows are automatically created when the data is inserted into the table. You define a table with a table name, such as employees
, and a set of columns. You give each column a column name, such as employee_id
, last_name
, and job_id
; a datatype, such as VARCHAR2
, DATE
, or NUMBER
; and a width. The width can be predetermined by the datatype, as in DATE
. If columns are of the NUMBER
datatype, define precision and scale instead of width. The table 1 below lists all the available datatypes in Oracle which can be used to define column types in a table.
Summary of Oracle Built-In Datatypes
Table 1. Summary of Oracle Built-In Datatypes
Datatype | Description | Column Length / Default Values |
| Fixed-length character data of length | Fixed for every row in the table (with trailing blanks); maximum size is 2000 bytes per row; default size is 1 byte per row. When neither |
| Variable-length character data, with maximum length | Variable for each row, up to 4000 bytes per row. When neither |
| Fixed-length Unicode character data of length | Fixed for every row in the table (with trailing blanks). The upper limit is 2000 bytes per row. Default |
| Variable-length Unicode character data of maximum length | Variable for each row. The upper limit is 4000 bytes per row. |
| Single-byte or multibyte character data. Both fixed-width and variable-width character sets are supported, and both use the | Up to 232 - 1 bytes * (database block size), or 4 gigabytes * block size. |
| Unicode national character set ( | Up to 232 - 1 bytes * (database block size), or 4 gigabytes * block size. |
| Variable-length character data. Provided for backward compatibility. | Variable for each row in the table, up to 231 - 1 bytes, or 2 gigabytes, per row. |
| 32-bit floating-point number. | 4 bytes. |
| 64-bit floating-point number. | 8 bytes. |
| Variable-length numeric data. Precision | Variable for each row. The maximum space available for a given column is 21 bytes per row. |
| Fixed-length date and time data, ranging from Jan. 1, 4712 B.C.E. to Dec. 31, 9999 C.E. | Fixed at 7 bytes for each row in the table. Default format is a string (such as |
| A period of time, represented as years and months. The | Fixed at 5 bytes. |
| A period of time, represented as days, hours, minutes, and seconds. The | Fixed at 11 bytes. |
| A value representing a date and time, including fractional seconds. (The exact resolution depends on the operating system clock.) The | Varies from 7 to 11 bytes, depending on the precision. The default is determined by the |
| A value representing a date and time, plus an associated time zone setting. The time zone can be an offset from UTC, such as ' The | Fixed at 13 bytes. The default is determined by the |
| Similar to The | Varies from 7 to 11 bytes, depending on |
| Unstructured binary data. | Up to 232 - 1 bytes * (database block size), or 4 gigabytes * block size |
| Address of a binary file stored outside the database. Enables byte-stream I/O access to external LOBs residing on the database server. | The referenced file can be up to 232 - 1 bytes * (database block size), or 4 gigabytes * block size. |
| Variable-length raw binary data. A | Variable for each row in the table, up to 2000 bytes per row. |
| Variable-length raw binary data. Provided for backward compatibility. | Variable for each row in the table, up to 231 - 1 bytes, or 2 gigabytes, per row. |
| Base 64 binary data representing a row address. Used primarily for values returned by the | Fixed at 10 bytes (extended |
| Base 64 binary data representing the logical address of a row in an index-organized table. The optional | Maximum size and default are both 4000 bytes. |
You can also specify rules for each column of a table. These rules are called integrity constraints. One example is a NOT NULL
integrity constraint. This constraint forces the column to contain a value in every row.
After you create a table, insert rows of data using SQL statements. Table data can then be queried, deleted, or updated using SQL.
Types of tables
There are four types of tables as mentioned below in table 2.
Table 2. Types of tables
Type of Table | Description |
Ordinary (heap-organized) table | This is the basic, general-purpose type of table, which is the primary subject of this chapter. Its data is stored as an unordered collection (heap) |
Clustered table | A clustered table is a table that is part of a cluster. A cluster is a group of tables that share the same data blocks because they share common columns and are often used together. |
Index-organized table | Unlike an ordinary (heap-organized) table, data for an index-organized table is stored in a B-tree index structure in a primary key sorted manner. Besides storing the primary key column values of an index-organized table row, each index entry in the B-tree stores the non-key column values as well. |
Partitioned table | Partitioned tables allow your data to be broken down into smaller, more manageable pieces called partitions, or even sub-partitions. Each partition can be managed individually, and can operate independently of the other partitions, thus providing a structure that can be better tuned for availability and performance. |
Restrictions to consider when Creating Tables
Here are some restrictions that may affect your table planning and usage:
· Tables containing object types cannot be imported into a pre-Oracle8 database.
· You cannot merge an exported table into a preexisting table having the same name in a different schema.
· You cannot move types and extent tables to a different schema when the original data still exists in the database.
· Oracle Database has a limit on the total number of columns that a table (or attributes that an object type) can have.
The table 2 below specifies the databse limits for the various scema objects.
Logical Database Limits
Item | Type | Limit |
| Maximum length | The |
Indexes | Maximum per table | Unlimited |
total size of indexed column | 75% of the database block size minus some overhead | |
Columns | Per table |
|
Per index (or clustered index) |
| |
Per bitmapped index |
| |
Constraints | Maximum per column | Unlimited |
Subqueries | Maximum levels of subqueries in a SQL statement | Unlimited in the
|
Partitions | Maximum length of linear partitioning key |
|
Maximum number of columns in partition key |
| |
Maximum number of partitions allowed per table or index |
| |
Rows | Maximum number per table | Unlimited |
Stored Packages | Maximum size | PL/SQL and Developer/2000 may have limits on the size of stored procedures they can call. The limits typically range from |
Trigger Cascade Limit | Maximum value | Operating system-dependent, typically |
Users and Roles | Maximum |
|
Tables | Maximum per clustered table |
|
Maximum per database | Unlimited |
Further, when you create a table that contains user-defined type data, the database maps columns of user-defined type to relational columns for storing the user-defined type data. This causes additional relational columns to be created. This results in "hidden" relational columns that are not visible in a DESCRIBE table statement and are not returned by a SELECT * statement. Therefore, when you create an object table, or a relational table with columns of REF, varray, nested table, or object type, be aware that the total number of columns that the database actually creates for the table can be more than those you specify.