Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
all labs.pdf
Скачиваний:
74
Добавлен:
25.02.2016
Размер:
2.04 Mб
Скачать

Explicit Data Type Conversion

TO_NUMBER TO_DATE

NUMBER

CHARACTER

DATE

 

 

 

TO_CHAR

 

TO_CHAR

Explicit Data Type Conversion

 

 

Academy

 

 

 

Copyright © 2009, Oracle. All rights reserved.

 

 

 

 

[nlsparams])

 

 

Oracle

 

SQL provides three functions to convert a value from one data type to another:

 

 

Function

 

Purpose

 

 

 

 

TO_CHAR(number|date,[ fmt],

Converts a number or date value to a VARCHAR2

 

 

 

 

 

 

Only

 

 

 

 

 

&

 

 

 

 

 

 

character stri g with the format model fmt

 

 

 

Internal

Number conversion: The nlsparams

 

 

 

parameter specifies the following characters,

 

 

 

 

Use

 

 

 

 

 

 

which are returned by number format elements:

 

 

 

 

 

Decimal character

 

 

 

 

Oracle

 

Group separator

 

 

 

 

Local currency symbol

 

 

 

 

 

 

 

 

 

 

International currency symbol

 

 

 

 

 

If nlsparams or any other parameter is omitted,

 

 

 

 

 

this function uses the default parameter values for

 

 

 

 

 

the session.

 

 

Oracle Database 11g: SQL Fundamentals I 4 - 7

Explicit Data Type Conversion

TO_NUMBER TO_DATE

NUMBER

CHARACTER

DATE

 

 

TO_CHAR

 

TO_CHAR

 

 

 

 

 

 

Copyright © 2009, Oracle. All rights reserved.

Academy

Explicit Data Type Conversion (continued)

 

 

Function

 

 

Purpose

 

 

 

 

 

 

 

 

 

 

 

 

 

TO_CHAR(number|date,[ fmt],

Date conve sion: The nlsparams parameter specifies

 

 

 

[nlsparams])

 

 

 

 

 

 

 

the language in which the month and day names, and

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Only

 

 

 

 

 

 

 

 

abbreviationsOracleare returned. If this parameter is omitted,

 

 

 

 

 

 

&

 

 

 

 

 

 

Internal

this function uses the default date languages for the

 

 

 

 

session.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TO_NUMBER(char,[fmt],

Use

 

 

 

 

 

[nlsparams])

 

 

Conv rts a character string containing digits to a number

 

 

 

 

 

 

in the format specified by the optional format model

 

.

 

 

 

 

 

The nlsparams parameter has the same purpose in this

 

 

 

Oracle

 

 

function as in the TO_CHAR function for number

 

 

 

 

 

 

omitted, the format is DD-MON-YY.

 

 

 

 

 

 

 

conversion.

 

 

 

 

 

TO DATE(char,[fmt],[nlspara

Converts a character string representing a date to a date

 

 

 

ms])

 

 

 

 

 

 

 

value according to the fmt that is specified. If fmt is

 

 

 

 

 

 

 

 

 

 

 

 

The nlsparams parameter has the same purpose in this

 

 

 

 

 

 

function as in the TO_CHAR function for date conversion.

 

 

 

Oracle Database 11g: SQL Fundamentals I 4 - 8

 

 

 

Explicit Data Type Conversion (continued)

Note: The list of functions mentioned in this lesson includes only some of the available conversion functions.

For more information, see the section on Conversion Functions in Oracle Database SQL Language Reference 11g, Release 1 (11.1).

 

Academy

Oracle

&

Only

Internal

 

Use

Oracle

 

Oracle Database 11g: SQL Fundamentals I 4 - 9

Lesson Agenda

Implicit and explicit data type conversion

TO_CHAR, TO_DATE, TO_NUMBER functions

Nesting functions

General functions:

NVL

NVL2

NULLIF

COALESCE

Conditional expressions:

CASE

DECODE

 

Copyright © 2009, Oracle. All rights reserved.

Academy

 

 

 

 

Oracle

&

Only

 

 

Internal

 

 

 

 

Use

 

Oracle

 

 

 

Oracle Database 11g: SQL Fundamentals I 4 - 10

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