Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5.06 Mб
Скачать

7.2 Overview of pl/sql Datatypes

Whenever you declare a variable or a constant, you must assign it a datatype. (PL/SQL is, with very few exceptions, a "strongly typed" language; see the sidebar for a definition.) PL/SQL offers a comprehensive set of predefined scalar and composite datatypes, and starting with Oracle8 you can create your ownuser-defined types (also known as abstract datatypes).

What Does "Strongly Typed" Mean?

"A strongly typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language, and all constants or variables defined for a given program must be described with one of the data types. Certain operations may be allowable only with certain data types. The language compiler enforces the data typing and use compliance. An advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and thus guarantees a certain consistency of results. A disadvantage is that it prevents the programmer from inventing a data type not anticipated by the developers of the programming language and it limits how "creative" one can be in using a given data type." (Definition courtesy of www.whatis.com)

Virtually all of these predefined datatypes are defined in the PL/SQL STANDARD package. Here, for example, are the statements that define the Boolean datatype and two of the numeric datatypes:

create or replace package STANDARD is

type BOOLEAN is (FALSE, TRUE);

type NUMBER is NUMBER_BASE;

subtype INTEGER is NUMBER(38,);

When it comes to datatypes, PL/SQL supports the "usual suspects" and a whole lot more. This section provides a quick overview of the various predefined datatypes. They are covered in detail in Chapter 8 through Chapter 12, Chapter 14, and Chapter 21; you will find detailed references to specific chapters in the following sections.

7.2.1 Character Data

PL/SQL supports both fixed- and variable-length strings as both traditional character and Unicode character data. CHAR and NCHAR are fixed-length datatypes; VARCHAR2 and NVARCHAR2 are variable-length datatypes. Here is a declaration of a variable-length string that can hold up to 2000 characters:

DECLARE

l_accident_description VARCHAR2(2000);

Chapter 8 explores the rules for character data, provides many examples, and explains the built-in functions provided to manipulate strings in PL/SQL.

Oracle also supports very large character strings, known as LONGs (pre-Oracle8) and LOBs (large objects) in Oracle8 and above. These datatypes allow you to store and manipulate very large amounts of data—a LOB can hold up to 4 GB of information. The character LOB datatypes are CLOB and NCLOB (multibyte format). CLOB stands for character large object, and NCLOB for National Language Support character large object.

There are, by the way, many rules restricting the use of LONGs. We recommend that you avoid using LONGs in all releases of the RDBMS from Oracle8 onwards.

Chapter 12 explores the rules for large objects, provides many examples, and explains the built-in functions and DBMS_LOB package provided to manipulate large objects in PL/SQL.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]