Purpose
This function calculates the hash value of the corresponding expression.
Syntax
ORA_HASH(expr [, max_bucket [, seed_value ]])
Parameters
Parameter |
Description |
|---|---|
| expr | Typically the name of a column in a database table. The data type can be numeric, character, datetime, or RAW. |
| max_bucket | The maximum bucket value returned by the hash function. Optional. The value range is [0, 4294967295], with the default value being 4294967295. |
| seed_value | A value that allows the database to generate different results for the same set of data. Optional. The value range is [0, 4294967295], with the default value being 0. |
Return type
Returns a value of the NUMBER data type.
Examples
Create a table named tbl1 and insert data into it. Query the col1 column of the tbl1 table using the ORA_HASH function, partition the hash values into up to 10 buckets, and set the third parameter to 5.
obclient> CREATE TABLE tbl1(col1 CHAR(6),col2 NUMBER(10,2));
Query OK, 0 rows affected
obclient> INSERT INTO tbl1 VALUES('ABC', 1000),('DEF', 1100),('GHI', 1200),('JKL', 1300),
('MNO', 1400),('PQR', 1500),('STU', 1600),('VWX', 1700),('YZ1', 1800),('234', 1900);
Query OK, 10 rows affected
Records: 10 Duplicates: 0 Warnings: 0
obclient> SELECT ORA_HASH(col1,10,5),col1,col2 FROM tbl1;
+---------------------+--------+------+
| ORA_HASH(COL1,10,5) | COL1 | COL2 |
+---------------------+--------+------+
| 5 | ABC | 1000 |
| 3 | DEF | 1100 |
| 8 | GHI | 1200 |
| 3 | JKL | 1300 |
| 3 | MNO | 1400 |
| 1 | PQR | 1500 |
| 4 | STU | 1600 |
| 2 | VWX | 1700 |
| 10 | YZ1 | 1800 |
| 5 | 234 | 1900 |
+---------------------+--------+------+
10 rows in set
