Home > Enterprise >  SQL Server equivalent of Oracle standard_hash function
SQL Server equivalent of Oracle standard_hash function

Time:09-28

I'm moving a database from Oracle to SQL Server and I can't figure out how to create this in SQL Server:

"MY_HASH" RAW(32) GENERATED ALWAYS AS (STANDARD_HASH("SSN"||'|'||TO_CHAR("DATE_OF_BIRTH",'DD-MON-RR'),'SHA256')) VIRTUAL ,

Thank you for your assistance.

CodePudding user response:

It seems that in SQL Server you would use the hashbytes function passing option 'SHA2_256' to generate the same value as Oracle's standard_hash with 'SHA256':

SQL Server 2019 (DBFiddle):

select hashbytes('SHA2_256','Text')

Oracle 18c (DBFiddle):

select standard_hash('Text', 'SHA256') from dual;

Both return

0x71988C4D8E0803BA4519F0B2864C1331C14A1890BF8694E251379177BFEDB5C3

This is a raw(32) value in Oracle and binary(32) (I think) in SQL Server, not a string, so it may be displayed differently depending on the client tool.

  • Related