Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / 3-single-functions.ppt
Скачиваний:
16
Добавлен:
12.05.2015
Размер:
310.78 Кб
Скачать

Conversioni Functionsi

Datatype conversion

Implicit datatype

Explicit datatype

conversion

conversion

3-22

ImplicitI li it Datatype Conversioni

For assignments, Oracle can automatically convert

From

 

To

 

 

 

VARCHAR2 or CHAR

 

NUMBER

 

 

 

VARCHAR2 or CHAR

 

DATE

 

 

 

NUMBER

 

VARCHAR2

 

 

 

DATE

 

VARCHAR2

 

 

 

3-23

ImplicitI li it Datatype Conversioni

For expression evaluation, Oracle can automatically convert

From

 

To

 

 

 

VARCHAR2 or CHAR

 

NUMBER

 

 

 

VARCHAR2 or CHAR

 

DATE

 

 

 

3-24

Explicitli it Datatype Conversioni

TO_NUMBER TO_DATE

NUMBER

CHARACTER

DATE

TO_CHAR TO_CHAR

3-25

TO_CHAR Functioni withi Dates

TO_CHAR(date, 'fmt')

The formatf r t modell::

Mustt be enclosedl inin singlei le quotationt ti marksr and isis case sensitiveiti

Can includei l any validlid datete formatf r t elementl t

Has an fmfm elementl t toto remover padded blanksl orr suppressr leadingl i zerosr

IsIs separatedr t fromfr thet datete valuel by a comma

3-26

Date Format Modell Elementsl

YYYY

Full year in numbers

 

 

YEAR

Year spelled out

 

 

MM

2-digit value for month

 

 

MONTH

Full name of the month

 

 

DY

3-letter abbreviation of the day

of the week

 

DAY

Full name of the day

 

 

3-27

Date Format Modell Elementsl

Time elements format the time portion of the date.

HH24:MI:SS AM

 

15:45:32 PM

Add character strings by enclosing them in double quotation marks.

DD "of" MONTH

 

12 of OCTOBER

Number suffixes spell out numbers.

ddspth

 

fourteenth

3-28

Usingi TO_CHAR Functioni

withi Dates

SQL> SELECT ename,

2 TO_CHAR(hiredate, 'fmDD Month YYYY') HIREDATE

3 FROM emp;

ENAME

HIREDATE

----------

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

KING

17

November 1981

BLAKE

1

May 1981

CLARK

9

June 1981

JONES

2

April 1981

MARTIN

28

September 1981

ALLEN

20

February 1981

...

 

 

14 rows selected.

3-29

TO_CHAR Functioni withi Numbers

TO_CHAR(number, 'fmt')

Use these formats with the TO_CHAR function to display a number value as a character.

9Represents a number

0 Forces a zero to be displayed

$Places a floating dollar sign

L Uses the floating local currency symbol

.Prints a decimal point

,Prints a thousand indicator

3-30

Usingi TO_CHAR Functioni

withi Numbers

 

 

 

 

 

 

SQL>

SELECT

TO_CHAR(sal,'$99,999') SALARY

 

 

2

FROM

emp

 

 

3

WHERE

ename = 'SCOTT';

 

 

 

 

 

 

 

 

 

 

 

SALARY

--------

$3,000

3-31

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