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

TRUNC (number)

TRUNC (number)

Syntax trunc_number::=

,

m

TRUNC ( n

)

Purpose

The TRUNC (number) function returns n truncated to m decimal places. If m is omitted, then n is truncated to 0 places. m can be negative to truncate (make zero) m digits left of the decimal point.

Examples

The following example truncate numbers:

SELECT TRUNC(15.79,1) "Truncate" FROM DUAL;

Truncate

----------

15.7

SELECT TRUNC(15.79,-1) "Truncate" FROM DUAL;

Truncate

----------

10

TRUNC (date)

Syntax trunc_date::=

 

 

,

fmt

TRUNC

(

date

)

6-194 Oracle9i SQL Reference

TZ_OFFSET

Purpose

The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. If you omit fmt, then date is truncated to the nearest day.

See Also: "ROUND and TRUNC Date Functions" on page 6-221 for the permitted format models to use in fmt

Examples

The following example truncates a date:

SELECT TRUNC(TO_DATE(’27-OCT-92’,’DD-MON-YY’), ’YEAR’)

"New Year" FROM DUAL;

New Year

---------

01-JAN-92

TZ_OFFSET

Syntax tz_offset::=

 

time_zone_name

 

 

 

 

+

 

 

 

 

hh

:

mi

TZ_OFFSET

(

 

 

)

SESSIONTIMEZONE

DBTMEZONE

Purpose

TZ_OFFSET returns the time zone offset corresponding to the value entered based on the date the statement is executed. You can enter a valid time zone name, a time zone offset from UTC (which simply returns itself), or the keyword SESSIONTIMEZONE or DBTIMEZONE. For a listing of valid values, query the TZNAME column of the V$TIMEZONE_NAMES dynamic performance view.

Functions 6-195

UID

See Also: Oracle9i Database Reference for information on the dynamic performance views

Examples

The following example returns the time zone offset of the US/Eastern time zone from UTC:

SELECT TZ_OFFSET(’US/Eastern’) FROM DUAL;

TZ_OFFS

-------

-04:00

UID

Syntax uid::=

UID

Purpose

UID returns an integer that uniquely identifies the session user (the user who logged on).

Examples

The following example returns the UID of the current user:

SELECT UID FROM DUAL;

UNISTR

Syntax unistr::=

UNISTR ( string )

6-196 Oracle9i SQL Reference

UPDATEXML

Purpose

UNISTR takes as its argument a string and returns it in the national character set.The national character set of the database can be either AL16UTF16 or UTF8. UNISTR provides support for Unicode string literals by letting you specify the Unicode encoding value of characters in the string. This is useful, for example, for inserting data into NCHAR columns.

The Unicode encoding value has the form ’\xxxx’ where ’xxxx’ is the hexadecimal value of a character in UCS-2 encoding format. To include the backslash in the string itself, precede it with another backslash (\\).

For portability and data preservation, Oracle Corporation recommends that in the UNISTR string argument you specify only ASCII characters and the Unicode encoding values.

See Also: Oracle9i Database Globalization Support Guide for information on Unicode and and national character sets

Examples

The following example passes both ASCII characters and Unicode encoding values to the UNISTR function, which returns the string in the national character set:

SELECT UNISTR(’abc\00e5\00f1\00f6’) FROM DUAL;

UNISTR

------

abcåñö

UPDATEXML

Syntax updatexml::=

 

 

 

 

 

,

,

namespace_string

 

 

 

 

 

 

UPDATEXML

(

XMLType_instance

,

XPath_string

,

value_expr

)

Purpose

UPDATEXML takes as arguments an XMLType instance and an XPath-value pair, and returns an XMLType instance with the updated value. If XPath_string is an XML element, then the corresponding value_expr must be an XMLType instance. If

Functions 6-197

UPDATEXML

XPath_string is an attribute or text node, then the value_expr can be any scalar datatype. The datatypes of the target of each XPath_string and its corresponding value_expr must match. The optional namespace_string must resolve to a VARCHAR2 value that specifies a default mapping or namespace mapping for prefixes, which Oracle uses when evaluating the XPath expression(s).

If you update an XML element to null, Oracle removes the attributes and children of the element, and the element becomes empty. If you update the text node of an element to null, Oracle removes the text value of the element, and the element itself remains but is empty.

In most cases, this function materializes an XML document in memory and updates the value. However, UPDATEXML is optimized for UPDATE statements on object-relational columns so that the function updates the value directly in the column. This optimization requires the following conditions:

The XMLType_instance must be the same as the column in the UPDATE ...

SET clause.

The XPath_string must resolve to scalar content.

Examples

The following example updates to 4 the number of docks in the San Francisco warehouse in the sample schema OE, which has a warehouse_spec column of type XMLType:

SELECT warehouse_name,

EXTRACT(warehouse_spec, ’/Warehouse/Docks’) "Number of Docks"

FROM warehouses

WHERE warehouse_name = ’San Francisco’;

WAREHOUSE_NAME

Number of Docks

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

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

San Francisco

<Docks>1</Docks>

UPDATE warehouses SET warehouse_spec = UPDATEXML(warehouse_spec, ’/Warehouse/Docks/text()’,4)

WHERE warehouse_name = ’San Francisco’;

1 row updated.

SELECT warehouse_name,

EXTRACT(warehouse_spec, ’/Warehouse/Docks’)

6-198 Oracle9i SQL Reference

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