Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

CEIL

WHERE p.employee_id = e.employee_id

ORDER BY p.project_name)

AS project_table_typ)

FROM emps_short e;

CEIL

Syntax ceil::=

CEIL ( n )

Purpose

CEIL returns smallest integer greater than or equal to n.

Examples

The following example returns the smallest integer greater than or equal to 15.7:

SELECT CEIL(15.7) "Ceiling" FROM DUAL;

Ceiling

----------

16

CHARTOROWID

Syntax chartorowid::=

CHARTOROWID ( char )

Purpose

CHARTOROWID converts a value from CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to ROWID datatype.

6-30 Oracle9i SQL Reference

CHR

Note: This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion. Please refer to "Datatype Comparison Rules" on page 2-45 for more information.

Examples

The following example converts a character rowid representation to a rowid. (The function will return a different rowid on different databases).

SELECT last_name FROM employees

WHERE ROWID = CHARTOROWID('AAAFd1AAFAAAABSAA/');

LAST_NAME

-------------------------

Greene

CHR

Syntax chr::=

 

 

USING

NCHAR_CS

CHR

(

n

)

Purpose

CHR returns the character having the binary equivalent to n in either the database character set or the national character set.

If USING NCHAR_CS is not specified, then this function returns the character having the binary equivalent to n as a VARCHAR2 value in the database character set.

If USING NCHAR_CS is specified, then this function returns the character having the binary equivalent to n as a NVARCHAR2 value in the national character set.

For single-byte character sets, if n > 256, then Oracle returns the binary equivalent of n mod 256. For multibyte character sets, n must resolve to one entire codepoint. Invalid codepoints are not validated, and the result of specifying invalid codepoints is indeterminate.

Functions 6-31

CHR

Note: Use of the CHR function (either with or without the optional USING NCHAR_CS clause) results in code that is not portable between ASCIIand EBCDIC-based machine architectures.

See Also: NCHR on page 6-100

Examples

The following example is run on an ASCII-based machine with the database character set defined as WE8ISO8859P1:

SELECT CHR(67)||CHR(65)||CHR(84) "Dog" FROM DUAL;

Dog

---

CAT

To produce the same results on an EBCDIC-based machine with the WE8EBCDIC1047 character set, the preceding example would have to be modified as follows:

SELECT CHR(195)||CHR(193)||CHR(227) "Dog"

FROM DUAL;

Dog

---

CAT

For multibyte character sets, this sort of concatenation gives different results. For example, given a multibyte character whose hexadecimal value is a1a2 (a1 representing the first byte and a2 the second byte), you must specify for n the decimal equivalent of ’a1a2’, or 41378. That is, you must specify:

SELECT CHR(41378) FROM DUAL;

You cannot specify the decimal equivalent of a1 concatenated with the decimal equivalent of a2, as in the following example:

SELECT CHR(161)||CHR(162) FROM DUAL;

However, you can concatenate whole multibyte codepoints, as in the following example, which concatenates the multibyte characters whose hexadecimal values are a1a2 and a1a3:

6-32 Oracle9i SQL Reference

COALESCE

SELECT CHR(41378)||CHR(41379) FROM DUAL;

The following example uses the UTF8 character set:

SELECT CHR (50052 USING NCHAR_CS) FROM DUAL;

CH

--

Ä

COALESCE

Syntax coalesce::=

 

 

,

 

COALESCE

(

expr

)

Purpose

COALESCE returns the first non-null expr in the expression list. At least one expr must not be the literal NULL. If all occurrences of expr evaluate to null, then the function returns null.

This function is a generalization of the NVL function.

You can also use COALESCE as a variety of the CASE expression. For example,

COALESCE (expr1, expr2)

is equivalent to:

CASE WHEN expr1 IS NOT NULL THEN expr1 ELSE expr2 END

Similarly,

COALESCE (expr1, expr2, ..., exprn), for n>=3

is equivalent to:

CASE WHEN expr1 IS NOT NULL THEN expr1

ELSE COALESCE (expr2, ..., exprn) END

Functions 6-33

Соседние файлы в папке Oracle selected docs