Oracle ORA_HASH() Function

Oracle ORA_HASH() is a built-in function that computes the hash value of a given expression.

Oracle ORA_HASH() Syntax

Here is the syntax of the Oracle ORA_HASH() function:

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

Parameters

expr

Required. The expression for which to calculate the hash value.

max_bucket

Optional. It determines the maximum bucket value that the hash function returns. You can specify any value between 0 and 4294967295. The default value is 4294967295.

seed_value

Optional. It allows Oracle to generate many different results for the same set of data. Oracle applies the hash function to the combination of expr and seed_value. You can specify any value between 0 and 4294967295. The default value is 0.

Return Value

The Oracle ORA_HASH() function returns the hash value of the given expression, a NUMBER data type.

If any argument is NULL, ORA_HASH() returns NULL.

Oracle ORA_HASH() Examples

Here are several examples that demonstrate how to use the Oracle ORA_HASH() function.

Basic Usage

SELECT
    ORA_HASH('HELLO')
FROM dual;

Output:

   ORA_HASH('HELLO')
____________________
           671553230

Maximum Bucket Value

The Oracle ORA_HASH() function allows you to specify the maximum bucket value that the hash function returns.

SELECT
    ORA_HASH('HELLO', 100),
    ORA_HASH('HELLO', 9999999)
FROM dual;

Output:

   ORA_HASH('HELLO',100)    ORA_HASH('HELLO',9999999)
________________________ ____________________________
                      89                      1553230

Seed

SELECT
    ORA_HASH('Hello', 999999, 1),
    ORA_HASH('Hello', 999999, 2)
FROM dual;

Output:

   ORA_HASH('HELLO',999999,1)    ORA_HASH('HELLO',999999,2)
_____________________________ _____________________________
                       123883                        331883

NULL Parameters

If any argument is NULL, ORA_HASH() returns NULL.

SET NULL 'NULL';
SELECT
    ORA_HASH(NULL) NULL_1,
    ORA_HASH(NULL, NULL) NULL_2,
    ORA_HASH(NULL, NULL, NULL) NULL_3
FROM dual;

Output:

   NULL_1    NULL_2    NULL_3
_________ _________ _________
     NULL      NULL      NULL

In this example, we use the SET NULL 'NULL'; statement to display the NULL values as the string 'NULL'.

Conclusion

Oracle ORA_HASH() is a built-in function that computes the hash value of a given expression.