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

Lesson Agenda

Single-row SQL functions

Character functions

Number functions

Working with dates

Date Functions

 

Copyright © 2009, Oracle. All rights reserved.

Academy

 

 

 

 

Oracle

&

Only

 

 

Internal

 

 

 

 

Use

 

Oracle

 

 

 

Oracle Database 11g: SQL Fundamentals I 3 - 15

Number Functions

ROUND: Rounds value to a specified decimal

TRUNC: Truncates value to a specified decimal

MOD: Returns remainder of division

Function

 

 

Result

 

 

 

ROUND(45.926,

2)

45.93

 

 

 

TRUNC(45.926,

2)

45.92

 

 

 

MOD(1600,

300)

100

 

 

 

 

 

Copyright © 2009, Oracle. All rights reserved.

Academy

Number Functions

 

Number functions accept numeric input and return numeric va u s. This section describes some of the number functions.

 

Function

Purpose

 

 

 

Oracle

 

ROUND(column|expression, n)

Rounds the column, expression, or value to n decimal

 

 

places or, if n is omitted, no decimal places (If n is

 

 

&

 

 

 

negative, numbers to the left of decimal point are rounded.)

 

 

 

Only

 

TRUNC(column|expression, )

Truncat s the column, expression, or value to n decimal

 

 

places or, if n is omitted, n defaults to zero

 

MOD(m,n)

Returns the remainder of m divided by n

 

 

Use

 

Internal

 

Note: This list contains only some of the

available number functions.

Oracle

 

 

For more information, see the section on Numeric Functions in Oracle Database SQL Language Reference 11g, Release 1 (11.1).

Oracle Database 11g: SQL Fundamentals I 3 - 16

The DUAL table is
DUAL Table

Using the ROUND Function

1

2

SELECT ROUND(45.923,2), ROUND(45.923,0),

ROUND(45.923,-1) 3

FROM DUAL;

 

 

 

 

 

 

 

1

2

3

 

 

DUAL is a dummy table that you can use to view results

 

from functions and calculations.

 

 

 

 

Copyright © 2009, Oracle. All rights reserved.

 

Using the ROUND Function

 

 

 

 

Academy

 

 

 

 

 

 

 

 

The ROUND function rounds the column, expression, or value to n d cimal places. If the second

 

 

 

Oracle

argument is 0 or is missing, the value is rounded to zero de imal places. If the second argument is 2, the value is rounded to two decimal places. Conversely, if the second argument is –2, the value is rounded to two decimal places to the left (rounded to the nearest unit of 100).

The function can also be used with date functions.OnlyYou will see examples later in this lesson.

ROUND &

DUMMY, and one row with the value X. The DUAL table is useful when you want to return a value

only once (for example, he value of a constant, pseudocolumn, or expression that is not derived from a table with user data). The DUAL table is generally used for completeness of the SELECT clause

Internalowned by the user and can be accessed by all users. It contains one column,

SYSUse

syntax, because both SELECT and FROM clauses are mandatory, and several calculations do not need Oracleto select from the actual tables.

Oracle Database 11g: SQL Fundamentals I 3 - 17

Copyright © 2009, Oracle. All rights reserved.
Using the TRUNC Function

Using the TRUNC Function

1

2

SELECT TRUNC(45.923,2), TRUNC(45.923),

TRUNC(45.923,-1) 3

FROM DUAL;

1

2

3

Academy The TRUNC function truncates the column, expression,Oracleor value to n decimal places.

The TRUNC function works with arguments similar to those of the ROUND function. If the second

argument is 0 or is missing, the value is truncated to ze o decimal places. If the second argument is 2, the value is truncated to two decimal places. Conversely, if the second argument is –2, the value is

truncated to two decimal places to the left. If the second argument is –1, the value is truncated to one

decimal place to the left.

&

Internal

Like the ROUND function, the TRUNC function can beOnlyused with date functions.

Oracle

Use

 

Oracle Database 11g: SQL Fundamentals I 3 - 18

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