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

REPLACE

REGR_SYY(s.amount_sold, s.quantity_sold)

OVER (ORDER BY t.fiscal_year, t.fiscal_month_desc) "Regr_syy", REGR_SXX(s.amount_sold, s.quantity_sold)

OVER (ORDER BY t.fiscal_year, t.fiscal_month_desc) "Regr_sxx" FROM sales s, times t

WHERE s.time_id = t.time_id AND prod_id IN (270, 260)

AND t.fiscal_month_desc = ’1998-02’ AND t.day_number_in_week IN (6,7)

ORDER BY t.day_number_in_month;

DAY_NUMBER_IN_MONTH Regr_sxy Regr_syy Regr_sxx

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

1 130973783 1.8916E+10 2577797.94

.

.

.

30 130973783 1.8916E+10 2577797.94

REPLACE

Syntax replace::=

 

 

 

 

,

replacement_string

REPLACE

(

char

,

search_string

)

Purpose

REPLACE returns char with every occurrence of search_string replaced with replacement_string. If replacement_string is omitted or null, then all occurrences of search_string are removed. If search_string is null, then char is returned.

Both search_string and replacement_string, as well as char, can be any of the datatypes CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The string returned is of VARCHAR2 datatype and is in the same character set as char.

This function provides functionality related to that provided by the TRANSLATE function. TRANSLATE provides single-character, one-to-one substitution. REPLACE lets you substitute one string for another as well as to remove character strings.

See Also: TRANSLATE on page 6-188

Functions 6-137

ROUND (number)

Examples

The following example replaces occurrences of "J" with "BL":

SELECT REPLACE(’JACK and JUE’,’J’,’BL’) "Changes"

FROM DUAL;

Changes

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

BLACK and BLUE

ROUND (number)

Syntax round_number::=

 

 

,

integer

ROUND

(

number

)

Purpose

ROUND returns number rounded to integer places right of the decimal point. If integer is omitted, then number is rounded to 0 places. integer can be negative to round off digits left of the decimal point. integer must be an integer.

Examples

The following example rounds a number to one decimal point:

SELECT ROUND(15.193,1) "Round" FROM DUAL;

Round

----------

15.2

The following example rounds a number one digit to the left of the decimal point:

SELECT ROUND(15.193,-1) "Round" FROM DUAL;

Round

----------

20

6-138 Oracle9i SQL Reference

ROW_NUMBER

ROUND (date)

Syntax round_date::=

 

 

,

fmt

ROUND

(

date

)

Purpose

ROUND returns date rounded to the unit specified by the format model fmt. If you omit fmt, then date is rounded to the nearest day.

See Also: "ROUND and TRUNC Date Functions" on page 6-221 for the permitted format models to use in fmt

Examples

The following example rounds a date to the first day of the following year:

SELECT ROUND (TO_DATE (’27-OCT-00’),’YEAR’)

"New Year" FROM DUAL;

New Year

---------

01-JAN-01

ROW_NUMBER

Syntax row_number::=

 

 

 

 

 

query_partition_clause

 

ROW_NUMBER

(

)

OVER

(

order_by_clause

)

See Also: "Analytic Functions" on page 6-10 for information on syntax, semantics, and restrictions

Functions 6-139

ROW_NUMBER

Purpose

ROW_NUMBER is an analytic function. It assigns a unique number to each row to which it is applied (either each row in the partition or each row returned by the query), in the ordered sequence of rows specified in the order_by_clause, beginning with 1.

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

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

Examples

For each department in the sample table oe.employees, the following example assigns numbers to each row in order of employee’s hire date:

SELECT department_id, last_name, employee_id, ROW_NUMBER()

OVER (PARTITION BY department_id ORDER BY employee_id) AS emp_id FROM employees;

DEPARTMENT_ID

LAST_NAME

EMPLOYEE_ID

EMP_ID

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

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

 

10

Whalen

200

1

 

20

Hartstein

201

1

 

20

Fay

202

2

 

30

Raphaely

114

1

 

30

Khoo

115

2

 

30

Baida

116

3

 

30

Tobias

117

4

 

30

Himuro

118

5

 

30

Colmenares

119

6

 

40

Mavris

203

1

.

 

 

 

 

.

 

 

 

 

.

100

Popp

113

6

 

 

110

Higgins

205

1

 

110

Gietz

206

2

ROW_NUMBER is a nondeterministic function. However, employee_id is a unique key, so the results of this application of the function are deterministic.

See Also: FIRST_VALUE on page 6-69 and LAST_VALUE on page 6-84 for examples of nondeterministic behavior

6-140 Oracle9i SQL Reference

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