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

TO_TIMESTAMP

Examples

The following example illustrates going from a multibyte ’A’ in UTF8 to a single byte ASCII ’A’:

SELECT TO_SINGLE_BYTE( CHR(15711393)) FROM DUAL;

T

-

A

TO_TIMESTAMP

Syntax to_timestamp::=

 

 

 

nlsparam

 

 

,

fmt

 

 

TO_TIMESTAMP

(

char

 

 

)

Purpose

TO_TIMESTAMP converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of TIMESTAMP datatype.

The optional fmt specifies the format of char. If you omit fmt, then char must be in the default format of the TIMESTAMP datatype. The optional ’nlsparam’ has the same purpose in this function as in the TO_CHAR function for date conversion.

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 string to a timestamp:

SELECT TO_TIMESTAMP (’1999-12-01 11:00:00’, ’YYYY-MM-DD HH:MI:SS’) FROM DUAL;

Functions 6-185

TO_TIMESTAMP_TZ

TO_TIMESTAMP(’1999-12-0111:00:00’,’YYYY-MM-DDHH:MI:SS’)

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

01-DEC-99 11.00.00.000000000 AM

TO_TIMESTAMP_TZ

Syntax to_timestamp_tz::=

 

 

 

nlsparam

 

 

,

fmt

 

 

TO_TIMESTAMP_TZ

(

char

 

 

)

Purpose

TO_TIMESTAMP_TZ converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of TIMESTAMP WITH TIME ZONE datatype.

Note: This function does not convert character strings to

TIMESTAMP WITH LOCAL TIME ZONE. To do this, use a CAST function, as shown in CAST on page 6-27.

The optional fmt specifies the format of char. If you omit fmt, then char must be in the default format of the TIMESTAMP WITH TIME ZONE datatype. The optional ’nlsparam’ has the same purpose in this function as in the TO_CHAR function for date conversion.

Examples

The following example converts a character string to a value of TIMESTAMP WITH TIME ZONE:

SELECT TO_TIMESTAMP_TZ(’1999-12-01 11:00:00 -8:00’, ’YYYY-MM-DD HH:MI:SS TZH:TZM’) FROM DUAL;

TO_TIMESTAMP_TZ(’1999-12-0111:00:00-08:00’,’YYYY-MM-DDHH:MI:SSTZH:TZM’)

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

01-DEC-99 11.00.00.000000000 AM -08:00

6-186 Oracle9i SQL Reference

TO_YMINTERVAL

The following example casts a null column in a UNION operation as TIMESTAMP WITH LOCAL TIME ZONE using the sample tables oe.order_items and oe.orders:

SELECT order_id, line_item_id,

CAST(NULL AS TIMESTAMP WITH LOCAL TIME ZONE) order_date

FROM order_items

UNION

SELECT order_id, to_number(null), order_date

FROM orders;

ORDER_ID

LINE_ITEM_ID

ORDER_DATE

----------

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

2354

1

 

2354

2

 

2354

3

 

2354

4

 

2354

5

 

2354

6

 

2354

7

 

2354

8

 

2354

9

 

2354

10

 

2354

11

 

2354

12

 

2354

13

 

2354

 

14-JUL-00 05.18.23.234567 PM

2355

1

 

2355

2

 

...

 

 

TO_YMINTERVAL

Syntax to_yminterval::=

TO_YMINTERVAL ( char )

Purpose

TO_YMINTERVAL converts a character string of CHAR, VARCHAR2, NCHAR, or

NVARCHAR2 datatype to an INTERVAL YEAR TO MONTH type, where char is the character string to be converted.

Functions 6-187

TRANSLATE

Examples

The following example calculates for each employee in the sample hr.employees table a date one year two months after the hire date:

SELECT hire_date, hire_date + TO_YMINTERVAL(’01-02’) "14 months" FROM employees;

HIRE_DATE 14 months

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

17-JUN-87 17-AUG-88 21-SEP-89 21-NOV-90 13-JAN-93 13-MAR-94 03-JAN-90 03-MAR-91 21-MAY-91 21-JUL-92

.

.

.

TRANSLATE

Syntax translate::=

TRANSLATE

(

char

,

from_string

,

to_string

)

Purpose

TRANSLATE returns char with all occurrences of each character in from_string replaced by its corresponding character in to_string. Characters in char that are not in from_string are not replaced. The argument from_string can contain more characters than to_string. In this case, the extra characters at the end of from_string have no corresponding characters in to_string. If these extra characters appear in char, then they are removed from the return value.

You cannot use an empty string for to_string to remove all characters in from_ string from the return value. Oracle interprets the empty string as null, and if this function has a null argument, then it returns null.

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.

6-188 Oracle9i SQL Reference

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