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

LEAST

a position of the cursor, LEAD provides access to a row at a given physical offset beyond that position.

If you do not specify offset, then its default is 1. The optional default value is returned if the offset goes beyond the scope of the table. If you do not specify default, then its default value is null.

You cannot use LEAD or any other analytic function for value_expr. That is, you can use other built-in function expressions for value_expr, but you cannot nest analytic functions.

See Also: "About SQL Expressions" on page 4-2 for information on valid forms of expr

Examples

The following example provides, for each employee in the employees table, the hire date of the employee hired just after:

SELECT last_name, hire_date,

LEAD(hire_date, 1) OVER (ORDER BY hire_date) AS "NextHired"

FROM employees WHERE department_id = 30;

LAST_NAME

HIRE_DATE NextHired

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

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

Raphaely

07-DEC-94

18-MAY-95

Khoo

18-MAY-95

24-JUL-97

Tobias

24-JUL-97

24-DEC-97

Baida

24-DEC-97

15-NOV-98

Himuro

15-NOV-98

10-AUG-99

Colmenares

10-AUG-99

 

LEAST

Syntax least::=

 

 

,

 

LEAST

(

expr

)

Functions 6-87

LENGTH

Purpose

LEAST returns the least of the list of exprs. All exprs after the first are implicitly converted to the datatype of the first expr before the comparison. Oracle compares the exprs using nonpadded comparison semantics. If the value returned by this function is character data, then its datatype is always VARCHAR2.

Examples

The following statement is an example of using the LEAST function:

SELECT LEAST(’HARRY’,’HARRIOT’,’HAROLD’) "LEAST"

FROM DUAL;

LEAST

------

HAROLD

LENGTH

Syntax length::=

LENGTH

LENGTHB

LENGTHC

(

char

)

LENGTH2

LENGTH4

Purpose

The "length" functions return the length of char. LENGTH calculates length using characters as defined by the input character set. LENGTHB uses bytes instead of characters. LENGTHC uses Unicode complete characters. LENGTH2 uses UCS2 codepoints. LENGTH4 uses UCS4 codepoints.

char can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or

NCLOB. The return value is of datatype NUMBER. If char has datatype CHAR, then the length includes all trailing blanks. If char is null, then this function returns null.

6-88 Oracle9i SQL Reference

LN

Examples

The following example uses the LENGTH function using a single-byte database character set.

SELECT LENGTH(’CANDIDE’) "Length in characters"

FROM DUAL;

Length in characters

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

7

This example assumes a double-byte database character set.

SELECT LENGTHB (’CANDIDE’) "Length in bytes"

FROM DUAL;

Length in bytes

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

14

LN

Syntax ln::=

LN ( n )

Purpose

LN returns the natural logarithm of n, where n is greater than 0.

Examples

The following example returns the natural logarithm of 95:

SELECT LN(95) "Natural log of 95" FROM DUAL;

Natural log of 95

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

4.55387689

Functions 6-89

LOCALTIMESTAMP

LOCALTIMESTAMP

Syntax localtimestamp::=

( timestamp_precision )

LOCALTIMESTAMP

Purpose

LOCALTIMESTAMP returns the current date and time in the session time zone in a value of datatype TIMESTAMP. The difference between this function and CURRENT_ TIMESTAMP is that LOCALTIMESTAMP returns a TIMESTAMP value while CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value.

See Also: CURRENT_TIMESTAMP on page 6-50

Examples

This example illustrates the difference between LOCALTIMESTAMP and CURRENT_ TIMESTAMP:

ALTER SESSION SET TIME_ZONE = ’-5:00’;

SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;

CURRENT_TIMESTAMP LOCALTIMESTAMP

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

04-APR-00 01.27.18.999220 PM -05:00 04-APR-00 01.27.19 PM

ALTER SESSION SET TIME_ZONE = ’-8:00’;

SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL;

CURRENT_TIMESTAMP LOCALTIMESTAMP

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

04-APR-00 10.27.45.132474 AM -08:00 04-APR-00 10.27.451 AM

If you use the LOCALTIMESTAMP with a format mask, take care that the format mask matches the value returned by the function. For example, consider the following table:

CREATE TABLE local_test (col1 TIMESTAMP WITH LOCAL TIME ZONE);

The following statement fails because the mask does not include the TIME ZONE portion of the return type of the function:

6-90 Oracle9i SQL Reference

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