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

 

 

SYS_XMLAGG

SELECT b.title, b.author.name, SYS_TYPEID(author)

"Type_ID" FROM books b;

 

 

TITLE

AUTHOR.NAME

Type_ID

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

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

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

An Autobiography

Bob

01

Business Rules

Joe

02

Mixing School and Work

Tim

03

You can use the SYS_TYPEID function to create an index on the type-discriminant column of a table. For an example, see "Indexing on Substitutable Columns: Examples" on page 13-93.

SYS_XMLAGG

Syntax

SYS_XMLAgg::=

 

 

 

fmt

SYS_XMLAGG

(

expr

)

Purpose

SYS_XMLAgg aggregates all of the XML documents or fragments represented by expr and produces a single XML document. It adds a new enclosing element with a default name ROWSET. If you want to format the XML document differently, then specify fmt, which is an instance of the XMLFormat object.

See Also:

"XML Format Model" on page 2-79 for using the attributes of the XMLFormat type to format SYS_XMLAgg results

SYS_XMLGEN on page 6-166

Oracle9i XML API Reference - XDK and Oracle XML DB and Oracle9i XML Developer’s Kits Guide - XDK for information on XML types and their use

Examples

The following example uses the SYS_XMLGen function to generate an XML document for each row of the sample table employees where the employee’s last

Functions 6-165

SYS_XMLGEN

name begins with the letter R, and then aggregates all of the rows into a single XML document in the default enclosing element ROWSET:

SELECT SYS_XMLAGG(SYS_XMLGEN(last_name))

FROM employees

WHERE last_name LIKE ’R%’;

SYS_XMLAGG(SYS_XMLGEN(LAST_NAME))

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

<ROWSET> <LAST_NAME>Raphaely</LAST_NAME> <LAST_NAME>Rogers</LAST_NAME> <LAST_NAME>Rajs</LAST_NAME> <LAST_NAME>Russell</LAST_NAME>

</ROWSET>

SYS_XMLGEN

Syntax

SYS_XMLGen::=

 

 

 

fmt

SYS_XMLGEN

(

expr

)

Purpose

SYS_XMLGen takes an expression that evaluates to a particular row and column of the database, and returns an instance of type XMLType containing an XML document. The expr can be a scalar value, a user-defined type, or an XMLType instance.

If expr is a scalar value, then the function returns an XML element containing the scalar value.

If expr is a type, then the function maps the user-defined type attributes to XML elements.

If expr is an XMLType instance, then the function encloses the document in an XML element whose default tag name is ROW.

By default the elements of the XML document match the elements of expr. For example, if expr resolves to a column name, then the enclosing XML element will be the same column name. If you want to format the XML document differently, then specify fmt, which is an instance of the XMLFormat object.

6-166 Oracle9i SQL Reference

SYSDATE

See Also:

"XML Format Model" on page 2-79 for a description of the XMLFormat type and how to use its attributes to format SYS_ XMLGen results

Oracle9i XML API Reference - XDK and Oracle XML DB and Oracle9i XML Developer’s Kits Guide - XDK for information on XML types and their use

Examples

The following example retrieves the employee email ID from the sample table oe.employees where the employee_id value is 205, and generates an instance of an XMLType containing an XML document with an EMAIL element.

SELECT SYS_XMLGEN(email)

FROM employees

WHERE employee_id = 205;

SYS_XMLGEN(EMAIL)

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

<EMAIL>SHIGGINS</EMAIL>

SYSDATE

Syntax sysdate::=

SYSDATE

Purpose

SYSDATE returns the current date and time. The datatype of the returned value is DATE. The function requires no arguments. In distributed SQL statements, this function returns the date and time on your local database. You cannot use this function in the condition of a CHECK constraint.

Examples

The following example returns the current date and time:

Functions 6-167

SYSTIMESTAMP

SELECT TO_CHAR

(SYSDATE, ’MM-DD-YYYY HH24:MI:SS’)"NOW" FROM DUAL;

NOW

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

04-13-2001 09:45:51

SYSTIMESTAMP

Syntax systimestamp::=

SYSTIMESTAMP

Purpose

SYSTIMESTAMP returns the system date, including fractional seconds and time zone of the system on which the database resides. The return type is TIMESTAMP WITH TIME ZONE.

Examples

The following example returns the system date.

SELECT SYSTIMESTAMP FROM DUAL;

SYSTIMESTAMP

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

28-MAR-00 12.38.55.538741 PM -08:00

The following example shows how to explicitly specify fractional seconds:

SELECT TO_CHAR(SYSTIMESTAMP, ’SSSS.FF’) FROM DUAL;

TO_CHAR(SYSTIM

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

5050.105900

6-168 Oracle9i SQL Reference

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