Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
all labs.pdf
Скачиваний:
66
Добавлен:
25.02.2016
Размер:
2.04 Mб
Скачать

Nesting Functions

Single-row functions can be nested to any level.

Nested functions are evaluated from the deepest level to the least deep level.

F3(F2(F1(col,arg1),arg2),arg3)

Step 1 = Result 1

Step 2 = Result 2

Step 3 = Result 3

 

Copyright © 2009, Oracle. All rights reserved.

Academy

Nesting Functions

 

 

Oracle

Single-row functions can be nested to any depth. Nested functions are evaluated from the innermost level to the outermost level. Some examples follow to show you the flexibility of these functions.

&

Only

Internal

 

Use

Oracle

 

Oracle Database 11g: SQL Fundamentals I 4 - 24

TO_CHAR(NEXT_DAY(ADD_MONTHS (hire_date, 6), 'FRIDAY'), 'fmDay, Month ddth, YYYY') "Next 6 Month Review"
employees hire_date;

Nesting Functions

SELECT last_name,

UPPER(CONCAT(SUBSTR (LAST_NAME, 1, 8), '_US'))

FROM employees

WHERE department_id = 60;

Copyright © 2009, Oracle. All rights reserved.

Academy

Nesting Functions (continued)

The slide example displays the last names of employees in departm nt 60. The evaluation of the SQL

Example:

statement involves three steps:

 

1.

The inner function retrieves the first eight characte s of the last name.

 

Result1 = SUBSTR (LAST_NAME, 1, 8)

2.

The outer function concatenates the result withOracleUS.

 

Result2 = CONCAT(Result1, ' US')

3.

&

 

The outermost function converts the results to uppercase.

 

 

Only

The entire expression becomes the column heading because no column alias was given.

 

Use

appear as Friday, AugustInternal13th, 1999. Order the results by hire date.

Display the date of the ext Friday that is six months from the hire date. The resulting date should

OracleSELECT

FROM

ORDER BY

Oracle Database 11g: SQL Fundamentals I 4 - 25

Lesson Agenda

Implicit and explicit data type conversion

TO_CHAR, TO_DATE, TO_NUMBER functions

Nesting functions

General functions:

NVL

NVL2

NULLIF

COALESCE

Conditional expressions:

CASE

DECODE

 

Copyright © 2009, Oracle. All rights reserved.

Academy

 

 

 

 

Oracle

&

Only

 

 

Internal

 

 

 

 

Use

 

Oracle

 

 

 

Oracle Database 11g: SQL Fundamentals I 4 - 26

General Functions

The following functions work with any data type and pertain to using nulls:

NVL (expr1, expr2)

NVL2 (expr1, expr2, expr3)

NULLIF (expr1, expr2)

COALESCE (expr1, expr2, ..., exprn)

 

 

 

Copyright © 2009, Oracle. All rights reserved.

Academy

General Functions

 

 

 

 

Oracle

These functions work with any data type and pertain to the use of null values in the expression list.

 

Function

Description

 

 

 

 

NVL

Converts a null value to an actual value

 

 

 

 

 

 

 

NVL2

If expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2

 

 

 

returns expr3

. The argument&expr1 can have any data type.

 

 

 

Internal

 

 

 

NULLIF

Compares two expressions and returnsOnlynull if they are equal; returns

 

 

 

 

Use

 

 

 

 

the first expression if they are not qual

 

 

 

COALESCE

Returns the fi st non-null expre sion in the expression list

 

Note: For more information about the hundreds of functions available, see the section on Functions

in Oracle Database SQL Language Reference 11g, Release 1 (11.1).

Oracle

Oracle Database 11g: SQL Fundamentals I 4 - 27

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]