How to call an external C function from a SQL stored procedure

errorsfunctionsstored-proceduresteradata

In Teradata 17, I am trying to call their own hash_md5 external function from my own SQL stored procedure:

replace procedure p()
sql security creator
begin
  declare l_hash varchar(32);
  set l_hash = hash_md5('abc');
end;

call p();

I get:

Failed [3706 : 42000] P:Syntax error: expected something between '(' and the string 'abc'.

I can call this function successfully in plain SQL:

select hash_md5('abc');

900150983CD24FB0D6963F7D28E17F72

I tried to pass a parameter in, instead of a hardcoded literal, but it made no difference.

enter image description here

Best Answer

hash_md5 is a C-UDF, which must be installed. Without qualified object name it will only be found if it's created in TD_SYSFNLIB or SYSLIB or the current session default database.

This should work:

set l_hash = mydb.hash_md5('abc');