The ORA_HASH function retrieves the hash value of a corresponding expression.
Syntax
ORA_HASH(expr [, max_bucket [, seed_value ] ])
Parameters
| Parameter | Description |
|---|---|
| expr | The value is generally a column name in the database table. The data type can be the numeric type, character type, date and time type, or RAW type. |
| max_bucket | The optional max_bucket parameter determines the maximum number of buckets that the hash function can return. Valid values: 0 to 4294967295. Default value: 4294967295. |
| seed_value | The optional seed_value parameter enables ApsaraDB for OceanBase to produce a number of different results for the same group of data. You can specify a value from 0 to 4294967295. Default value: 0. |
Return type
Data of the NUMBER type
Examples
To create the SALE table and insert data into the table, execute the following statements:
CREATE TABLE SALE(MONTH CHAR(6), SELL NUMBER(10,2));
INSERT INTO SALE VALUES(200001, 1000);
INSERT INTO SALE VALUES(200002, 1100);
INSERT INTO SALE VALUES(200003, 1200);
INSERT INTO SALE VALUES(200004, 1300);
INSERT INTO SALE VALUES(200005, 1400);
INSERT INTO SALE VALUES(200006, 1500);
INSERT INTO SALE VALUES(200007, 1600);
INSERT INTO SALE VALUES(200101, 1100);
INSERT INTO SALE VALUES(200202, 1200);
INSERT INTO SALE VALUES(200301, 1300);
To use the ORA_HASH function to query the SALE table, execute the following statement:
SELECT ORA_HASH(CONCAT(month,sell),12,0), month, sell FROM Sale;
The following query result is returned:
+-----------------------------------+--------+------+
| ORA_HASH(CONCAT(MONTH,SELL),12,0) | MONTH | SELL |
+-----------------------------------+--------+------+
| 1 | 200001 | 1000 |
| 6 | 200002 | 1100 |
| 5 | 200003 | 1200 |
| 4 | 200004 | 1300 |
| 5 | 200005 | 1400 |
| 2 | 200006 | 1500 |
| 7 | 200007 | 1600 |
| 10 | 200101 | 1100 |
| 7 | 200202 | 1200 |
| 4 | 200301 | 1300 |
+-----------------------------------+--------+------+