I am using sh2 function to generate the hash value but It is generating null/empty if any of the column value has null/empty.
For example
Input
select sha2(NULL, 256);
Output
NULL
is there any way to generate value even when the value inside sha2 function is empty/null.
NULL in SQL, means no value, so the result you are getting is expected.
You can create a query that will check for NULLs and return some predefined or random output for them, depending on what value you want, and the hash when there is the actual value. Example:
Create some test data:
Return hash when it is not NULL
Output:
Alternatively, you can output some random hash instead of a predefined string:
Output: