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

VAR_SAMP

CALENDAR Var_Pop Var_Samp

--------

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

1998-01

0

 

1998-02

6.1321E+11

1.2264E+12

1998-03

4.7058E+11

7.0587E+11

1998-04

4.6929E+11

6.2572E+11

1998-05

1.5524E+12

1.9405E+12

1998-06

2.3711E+12

2.8453E+12

1998-07

3.7464E+12

4.3708E+12

1998-08

3.7852E+12

4.3260E+12

1998-09

3.5753E+12

4.0222E+12

1998-10

3.4343E+12

3.8159E+12

1998-11

3.4245E+12

3.7669E+12

1998-12

4.8937E+12

5.3386E+12

VAR_SAMP

Syntax var_samp::=

OVER ( analytic_clause )

VAR_SAMP ( expr )

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

Purpose

VAR_SAMP returns the sample variance of a set of numbers after discarding the nulls in this set. You can use it as both an aggregate and analytic function.

The expr is a number expression, and the function returns a value of type NUMBER. If the function is applied to an empty set, then it returns null. The function makes the following calculation:

(SUM(expr2) - SUM(expr)2 / COUNT(expr)) / (COUNT(expr) - 1)

This function is similar to VARIANCE, except that given an input set of one element, VARIANCE returns 0 and VAR_SAMP returns null.

6-204 Oracle9i SQL Reference

VAR_SAMP

See Also:

"Aggregate Functions" on page 6-8

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

Aggregate Example

The following example returns the sample variance of the salaries in the sample employees table.

SELECT VAR_SAMP(salary) FROM employees;

VAR_SAMP(SALARY)

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

15283140.5

Analytic Example

The following example calculates the cumulative population and sample variances of the monthly sales in 1998:

SELECT t.calendar_month_desc, VAR_POP(SUM(s.amount_sold))

OVER (ORDER BY t.calendar_month_desc) "Var_Pop", VAR_SAMP(SUM(s.amount_sold))

OVER (ORDER BY t.calendar_month_desc) "Var_Samp" FROM sales s, times t

WHERE s.time_id = t.time_id AND t.calendar_year = 1998 GROUP BY t.calendar_month_desc;

CALENDAR Var_Pop Var_Samp

--------

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

1998-01

0

 

1998-02

6.1321E+11

1.2264E+12

1998-03

4.7058E+11

7.0587E+11

1998-04

4.6929E+11

6.2572E+11

1998-05

1.5524E+12

1.9405E+12

1998-06

2.3711E+12

2.8453E+12

1998-07

3.7464E+12

4.3708E+12

1998-08

3.7852E+12

4.3260E+12

1998-09

3.5753E+12

4.0222E+12

1998-10

3.4343E+12

3.8159E+12

1998-11

3.4245E+12

3.7669E+12

1998-12

4.8937E+12

5.3386E+12

Functions 6-205

VARIANCE

VARIANCE

Syntax variance::=

 

DISTINCT

 

 

 

 

 

 

ALL

 

OVER

(

analytic_clause

)

VARIANCE

(

expr

)

 

 

 

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

Purpose

VARIANCE returns variance of expr. You can use it as an aggregate or analytic function.

Oracle calculates the variance of expr as follows:

0 if the number of rows in expr = 1

VAR_SAMP if the number of rows in expr > 1

If you specify DISTINCT, then you can specify only the query_partition_ clause of the analytic_clause. The order_by_clause and windowing_ clause are not allowed.

See Also:

"Aggregate Functions" on page 6-8

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

Aggregate Example

The following example calculates the variance of all salaries in the sample employees table:

SELECT VARIANCE(salary) "Variance"

FROM employees;

Variance

----------

15283140.5

6-206 Oracle9i SQL Reference

VSIZE

Analytic Example

The query returns the cumulative variance of salary values in Department 30 ordered by hire date.

SELECT last_name, salary, VARIANCE(salary)

OVER (ORDER BY hire_date) "Variance"

FROM employees

WHERE department_id = 30;

LAST_NAME

SALARY

Variance

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

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

Raphaely

11000

0

Khoo

3100

31205000

Tobias

2800

21623333.3

Baida

2900

16283333.3

Himuro

2600

13317000

Colmenares

2500

11307000

VSIZE

Syntax vsize::=

VSIZE ( expr )

Purpose

VSIZE returns the number of bytes in the internal representation of expr. If expr is null, then this function returns null.

Note: This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion. Please refer to "Datatype Comparison Rules" on page 2-45 for more information.

Examples

The following example returns the number of bytes in the last_name of the employee in department 10:

Functions 6-207

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