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

Datetime Expressions

before number :=0; after number:=0;

begin loop

fetch cur into emp_hiredate; exit when cur%NOTFOUND;

if emp_hiredate > mgr_hiredate then after:=after+1;

else before:=before+1;

end if; end loop; close cur;

if before > after then return 1;

else

return 0; end if;

end;

/

The function accepts a cursor and a date. The function expects the cursor to be a query returning a set of dates. The following query uses the function to find those managers in the sample employees table, most of whose employees were hired before the manager.

SELECT e1.last_name FROM employees e1 WHERE f(

CURSOR(SELECT e2.hire_date FROM employees e2 WHERE e1.employee_id = e2.manager_id), e1.hire_date) = 1;

LAST_NAME

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

De Haan

Mourgos Cambrault Zlotkey Higgens

Datetime Expressions

A datetime expression yields a value of one of the datetime datatypes.

Expressions 4-9

Datetime Expressions

datetime_expression::=

 

LOCAL

 

 

 

 

 

 

 

 

 

 

 

+

 

 

 

 

datetime_value_expr

AT

 

 

 

 

 

 

 

 

hh

:

mm

 

 

 

 

 

 

 

DBTIMEZONE

 

 

 

 

 

TIME

ZONE

SESSIONTIMEZONE

 

 

 

 

 

 

 

time_zone_name

 

 

 

 

 

 

expr

 

 

 

 

 

A datetime_value_expr can be a datetime column or a compound expression that yields a datetime value. Datetimes and intervals can be combined according to the rules defined in Table 2–5 on page 2-25. The three combinations that yield datetime values are valid in a datetime expression.

If you specify AT LOCAL, Oracle uses the current session time zone.

The settings for AT TIME ZONE are interpreted as follows:

The string ’(+|-)HH:MM’ specifies a time zone as an offset from UTC.

DBTIMEZONE: Oracle uses the database time zone established (explicitly or by default) during database creation.

SESSIONTIMEZONE: Oracle uses the session time zone established by default or in the most recent ALTER SESSION statement.

time_zone_name: Oracle returns the datetime_value_expr in the time zone indicated by time_zone_name. For a listing of valid time zone names, query the V$TIMEZONE_NAMES dynamic performance view.

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

expr: If expr returns a character string with a valid time zone format, Oracle returns the input in that time zone. Otherwise, Oracle returns an error.

Example The following example converts the datetime value of one time zone to another time zone:

SELECT FROM_TZ(CAST(TO_DATE(’1999-12-01 11:00:00’,

4-10 Oracle9i SQL Reference

INTERVAL Expressions

’YYYY-MM-DD HH:MI:SS’) AS TIMESTAMP), ’America/New_York’)

AT TIME ZONE ’America/Los_Angeles’ "West Coast Time"

FROM DUAL;

West Coast Time

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

01-DEC-99 08.00.00.000000 AM AMERICA/LOS_ANGELES

Function Expressions

You can use any built-in SQL function or user-defined function as an expression. Some valid built-in function expressions are:

LENGTH(’BLAKE’)

ROUND(1234.567*43)

SYSDATE

See Also: "SQL Functions" on page 6-2 and "Aggregate

Functions" on page 6-8 for information on built-in functions

A user-defined function expression specifies a call to:

A function in an Oracle-supplied package (see Oracle9i Supplied PL/SQL Packages and Types Reference)

A function in a user-defined package or type or in a standalone user-defined function (see "User-Defined Functions" on page 6-222)

A user-defined function or operator (see CREATE OPERATOR on page 14-44, CREATE FUNCTION on page 13-52, and Oracle9i Data Cartridge Developer’s Guide)

Some valid user-defined function expressions are:

circle_area(radius) payroll.tax_rate(empno)

hr.employees.comm_pct(dependents, empno)@remote DBMS_LOB.getlength(column_name) my_function(DISTINCT a_column)

INTERVAL Expressions

An interval expression yields a value of INTERVAL YEAR TO MONTH or INTERVAL DAY TO SECOND.

Expressions 4-11

Object Access Expressions

interval_expression::=

DAY TO SECOND

interval_value_expr

YEAR TO MONTH

The interval_value_expr can be the value of an INTERVAL column or a compound expression that yields an interval value. Datetimes and intervals can be combined according to the rules defined in Table 2–5 on page 2-25. The six combinations that yield interval values are valid in an interval expression.

For example, the following statement subtracts the value of the order_date column in the sample table orders (a datetime value) from the system timestamp (another datetime value) to yield an interval value expression:

SELECT (SYSTIMESTAMP - order_date) DAY TO SECOND from orders;

Object Access Expressions

An object access expression specifies attribute reference and method invocation.

object_access_expression::=

,

argument

.

.

method

(

)

attribute

table_alias . column .

object_table_alias

.

 

,

 

 

(

expr

)

.

 

argument

(

)

 

 

 

method

The column parameter can be an object or REF column. If you specify expr, it must resolve to an object type.

When a type’s member function is invoked in the context of a SQL statement, if the SELF argument is null, Oracle returns null and the function is not invoked.

Examples The following example creates a table based on the sample oe.order_ item_typ object type, and then shows how you would update and select from the object column attributes.

4-12 Oracle9i SQL Reference

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