Codec functions

Updated at:

PolarDB for Oracle supports three codec functions: VSIZE, ORA_HASH, and DUMP.

VSIZE

Returns the number of bytes in the internal representation of expr.

Syntax

VSIZE(expr)

Parameters

ParameterDescription
exprThe expression to evaluate. Accepts character and numeric data types. Does not directly support CLOB; pass CLOB values through implicit data type conversion.

Return value

Returns a NUMBER value. Returns NULL if expr is NULL.

Example

SELECT VSIZE('0xffffffffffffffff'::xid8) FROM DUAL;
 vsize
-------
     8

ORA_HASH

Computes a hash value for an expression. Use this function to analyze data subsets and generate random samples.

Syntax

ORA_HASH(expr [, max_bucket [, seed_value]])

Parameters

ParameterDescription
exprThe expression to hash. Typically a column name. Accepts NUMBER, XML, CHARACTER, DATE, and RAW data types.
max_bucketOptional. The maximum bucket value the hash function returns. Valid values: 0–4294967295. Default: 4294967295.
seed_valueOptional. The database applies the hash function to the combination of expr and seed_value, producing different results for the same data when the seed differs. Valid values: 0–4294967295. Default: 0.

Return value

Returns a NUMBER value.

Examples

The following example creates a table with multiple column types and shows ORA_HASH results for an XML column and a rowid column.

create table t(
	xml xmltype,
	dp double precision,
	id rowid,
	si smallint,
	i integer,
	bi bigint,
	dec decimal,
	num number,
	r real,
	m money,
	c char(4),
	vc varchar,
	vc1 clob,
	te text,
	ts timestamp,
	da date,
	byt bytea,
	blc blob,
	ble blob,
	b bool);
insert into t values('xml',1,1,1,1,1,1,1,1,1,'a','abc','history','abc','2004-10-19 10:23:54','2004-10-19', 'DEADBEEF', cast(repeat('a', 5120) as bytea), cast(repeat('a', 5120) as bytea), true);

select ora_hash(xml) from t;
 ora_hash
----------
 22411469

select ora_hash(id) from t;
  ora_hash
------------
 2389907270

DUMP

Returns a VARCHAR2 value containing the data type code, byte length, and internal representation of expr. The result is always in the database character set.

Syntax

DUMP(expr[, return_fmt [, start_position [, length]]])

Parameters

ParameterDescription
exprThe expression to analyze. Supports various data types.
return_fmtOptional. The numeric format for the internal representation. Valid values: 8 (octal), 10 (decimal, default), 16 (hexadecimal), 17 (single character — printed as an ASCII or EBCDIC character when printable; otherwise printed in hexadecimal; NLS parameters are ignored).
start_positionOptional. The byte position at which to start returning data. Default: 1.
lengthOptional. The number of bytes to return. Default: all bytes.

Return value

Returns a VARCHAR2 value. Returns NULL if expr is NULL.

Examples

Hexadecimal dump of a numeric value:

select dump(123, 16, 0) FROM DUAL;
          dump
------------------------
 Typ=23 Len=4: 7b,0,0,0

Decimal dump of a string value:

select dump('abc', 10) FROM DUAL;