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

NLSSORT

NLSSORT

Syntax nlssort::=

 

 

,

nlsparam

NLSSORT

(

char

 

 

)

Purpose

NLSSORT returns the string of bytes used to sort char.

Both char and ’nlsparam’ can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2. The string returned is of RAW datatype.

The value of ’nlsparams’ can have the form

’NLS_SORT = sort’

where sort is a linguistic sort sequence or BINARY. If you omit ’nlsparams’, then this function uses the default sort sequence for your session. If you specify BINARY, then this function returns char.

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

This function can be used to specify comparisons based on a linguistic sort sequence rather than on the binary value of a string. The following example creates a test table containing two values and shows how the values returned can be ordered by the NLSSORT function:

CREATE TABLE test (name VARCHAR2(15));

INSERT INTO test VALUES (’Gaardiner’);

INSERT INTO test VALUES (’Gaberd’);

SELECT * FROM test ORDER BY name;

Functions 6-107

NLS_UPPER

NAME

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

Gaardiner Gaberd

SELECT * FROM test

ORDER BY NLSSORT(name, ’NLS_SORT = XDanish’);

NAME

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

Gaberd Gaardiner

See Also: Oracle9i Database Globalization Support Guide for information on sort sequences

NLS_UPPER

Syntax nls_upper::=

 

 

,

nlsparam

NLS_UPPER

(

char

 

 

)

Purpose

NLS_UPPER returns char, with all letters uppercase.

Both char and ’nlsparam’ 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.

The ’nlsparam’ can have the same form and serve the same purpose as in the

NLS_INITCAP function.

Examples

The following example returns a string with all the letters converted to uppercase:

SELECT NLS_UPPER (’große’) "Uppercase"

FROM DUAL;

6-108 Oracle9i SQL Reference

NTILE

Upper

-----

GROßE

SELECT NLS_UPPER (’große’, ’NLS_SORT = XGerman’) "Uppercase"

FROM DUAL;

Upperc

------

GROSSE

See Also: NLS_INITCAP on page 6-104

NTILE

Syntax ntile::=

 

 

 

 

 

 

query_partition_clause

 

NTILE

(

expr

)

OVER

(

order_by_clause

)

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

Purpose

NTILE is an analytic function. It divides an ordered dataset into a number of buckets indicated by expr and assigns the appropriate bucket number to each row. The buckets are numbered 1 through expr, and expr must resolve to a positive constant for each partition.

The number of rows in the buckets can differ by at most 1. The remainder values (the remainder of number of rows divided by buckets) are distributed one for each bucket, starting with bucket 1.

If expr is greater than the number of rows, then a number of buckets equal to the number of rows will be filled, and the remaining buckets will be empty.

You cannot use NTILE 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

Functions 6-109

NULLIF

Examples

The following example divides into 4 buckets the values in the salary column of the oe.employees table from Department 100. The salary column has 6 values in this department, so the two extra values (the remainder of 6 / 4) are allocated to buckets 1 and 2, which therefore have one more value than buckets 3 or 4.

SELECT last_name, salary, NTILE(4) OVER (ORDER BY salary DESC) AS quartile FROM employees

WHERE department_id = 100;

LAST_NAME

SALARY

QUARTILE

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

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

Greenberg

12000

1

Faviet

9000

1

Chen

8200

2

Urman

7800

2

Sciarra

7700

3

Popp

6900

4

NULLIF

Syntax nullif::=

NULLIF ( expr1 , expr2 )

Purpose

NULLIF compares expr1 and expr2. If they are equal, then the function returns null. If they are not equal, then the function returns expr1. You cannot specify the literal NULL for expr1.

The NULLIF function is logically equivalent to the following CASE expression:

CASE WHEN expr1 = expr 2 THEN NULL ELSE expr1 END

See Also: "CASE Expressions" on page 4-6

Examples

The following example selects those employees from the sample schema hr who have changed jobs since they were hired, as indicated by a job_id in the job_ history table different from the current job_id in the employees table:

6-110 Oracle9i SQL Reference

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