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

3.3.2 Whitespace and Keywords

Identifiers must be separated by at least one space or by a delimiter, but you can format your text by adding additional spaces, line breaks (newlines and/or carriage returns), and tabs wherever you can put a space, without changing the meaning of your entry.

The two statements shown below are therefore equivalent:

IF too_many_orders

THEN

warn_user;

ELSIF no_orders_entered

THEN

prompt_for_orders;

END IF;

IF too_many_orders THEN warn_user;

ELSIF no_orders_entered THEN prompt_for_orders;

END IF;

You may not, however, place a space or carriage return or tab within a lexical unit, such as a compound delimiter like the "not equals" symbol (!=). The following statement raises a compile error:

IF max_salary ! = min_salary THEN

because there is a space between the ! and the =.

3.4 Literals

A literal is a value that is not represented by an identifier; it is simply a value. A literal may be composed of one of the following types of data:

Number

415, 21.6, or NULL

String

`This is my sentence' or `01-FEB-2003' or NULL

Boolean

TRUE, FALSE, or NULL

Notice that there is no direct way to code a true date literal. The value `01-FEB-2003' is a string literal (any sequence of characters enclosed by single quotes). You can convert such a string to a date in PL/SQL or SQL, but a date has only an internal binary representation in Oracle.

A string literal can be composed of zero or more characters from the PL/SQL character set. A literal of zero characters is represented as '' (two consecutive single quotes with no characters between them). At least through Oracle9i, this zero-length string literal has the value NULL,[3] and a datatype of CHAR (fixed-length string).

[3] Don't be fooled by the inconsistent Oracle documentation, which states that a zero-length string is not the same as NULL, as in the ANSI standard.

Unlike identifiers, string literals in PL/SQL arecase-sensitive. The following two literals are different:

'Steven'

'steven'

The following condition, for example, evaluates to FALSE:

IF 'Steven' = 'steven'

3.4.1 Embedding Single Quotes Inside a String

The trickiest part of working with string literals comes when you need to include a single quote inside a string literal (as part of the literal itself). Generally, the rule is that you write two single quotes next to each other inside a string if you want the literal to contain a single quote in that position. The following table shows the literal in one column and the resulting "internal" string in the second column:

Literal

Actual value

'There''s no business like show business.'

There's no business like show business.

'"Hound of the Baskervilles"'

"Hound of the Baskervilles"

'NLS_LANGUAGE=''ENGLISH'''

NLS_LANGUAGE='ENGLISH'

''''

'

'''hello'''

'hello'

''''''

''

Here's a summary of how to embed single quotes in a literal:

  • To place a single quote inside the literal, put two single quotes together.

  • To place a single quote at the beginning or end of a literal, put three single quotes together.

  • To create a string literal consisting of one single quote, put four single quotes together.

  • To create a string literal consisting of two single quotes together, put six single quotes together.

Two single quotes together is not the same as a double quote character. A double quote character does not have any special significance inside a string literal. It is treated the same as a letter or number.

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