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

RATIO_TO_REPORT

RATIO_TO_REPORT

Syntax ratio_to_report::=

 

 

 

 

 

 

query_partition_clause

RATIO_TO_REPORT

(

expr

)

OVER

(

)

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

Purpose

RATIO_TO_REPORT is an analytic function. It computes the ratio of a value to the sum of a set of values. If expr evaluates to null, then the ratio-to-report value also evaluates to null.

The set of values is determined by the query_partition_clause. If you omit that clause, then the ratio-to-report is computed over all rows returned by the query.

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

The following example calculates the ratio-to-report value of each purchasing clerk’s salary to the total of all purchasing clerks’ salaries:

SELECT last_name, salary, RATIO_TO_REPORT(salary) OVER () AS rr FROM employees

WHERE job_id = ’PU_CLERK’;

LAST_NAME

SALARY

RR

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

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

Khoo

3100

.223021583

Baida

2900

.208633094

Tobias

2800

.201438849

Himuro

2600

.18705036

Colmenares

2500

.179856115

Functions 6-125

RAWTOHEX

RAWTOHEX

Syntax rawtohex::=

RAWTOHEX ( raw )

Purpose

RAWTOHEX converts raw to a character value containing its hexadecimal equivalent. The raw argument can be either RAW or BLOB datatype.

Examples

The following hypothetical example returns the hexadecimal equivalent of a RAW column value:

SELECT RAWTOHEX(raw_column) "Graphics"

FROM graphics;

Graphics

--------

7D

See Also: "RAW and LONG RAW Datatypes" on page 2-27 and

HEXTORAW on page 6-77

RAWTONHEX

Syntax rawtonhex::=

RAWTONHEX ( raw )

Purpose

RAWTONHEX converts raw to an NVARCHAR2 character value containing its hexadecimal equivalent.

6-126 Oracle9i SQL Reference

REF

Examples

The following hypothetical example returns the hexadecimal equivalent of a RAW column value:

SELECT RAWTONHEX(raw_column),

DUMP ( RAWTONHEX (raw_column) ) "DUMP"

FROM graphics;

RAWTONHEX(RA)

DUMP

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

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

7D

Typ=1 Len=4: 0,55,0,68

REF

Syntax ref::=

REF ( correlation_variable )

Purpose

REF takes as its argument a correlation variable (table alias) associated with a row of an object table or an object view. A REF value is returned for the object instance that is bound to the variable or row.

Examples

The sample schema oe contains a type called cust_address_typ, described as follows:

Attribute

Type

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

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

STREET_ADDRESS

VARCHAR2(40)

POSTAL_CODE

VARCHAR2(10)

CITY

VARCHAR2(30)

STATE_PROVINCE

VARCHAR2(10)

COUNTRY_ID

CHAR(2)

The following example creates a table based on the sample type oe.cust_ address_typ, inserts a row into the table, and retrieves a REF value for the object instance of the type in the addresses table:

Functions 6-127

REFTOHEX

CREATE TABLE addresses OF cust_address_typ;

INSERT INTO addresses VALUES (

’123 First Street’, ’4GF H1J’, ’Our Town’, ’Ourcounty’, ’US’);

SELECT REF(e) FROM addresses e;

REF(E)

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

00002802097CD1261E51925B60E0340800208254367CD1261E51905B60E034080020825436010101820000

See Also: Oracle9i Database Concepts

REFTOHEX

Syntax reftohex::=

REFTOHEX ( expr )

Purpose

REFTOHEX converts argument expr to a character value containing its hexadecimal equivalent. expr must return a REF.

Examples

The sample schema oe contains a warehouse_typ. The following example builds on that type to illustrate how to convert the REF value of a column to a character value containing its hexadecimal equivalent:

CREATE TABLE warehouse_table OF warehouse_typ (PRIMARY KEY (warehouse_id));

CREATE TABLE location_table

(location_number NUMBER, building REF warehouse_typ SCOPE IS warehouse_table);

INSERT INTO warehouse_table VALUES (1, ’Downtown’, 99);

INSERT INTO location_table SELECT 10, REF(w) FROM warehouse_table w;

SELECT REFTOHEX(building) FROM location_table;

6-128 Oracle9i SQL Reference

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