I have a Snowflake SQL stored procedure from where I’m trying to call the SYSTEM$SEND_EMAIL function, but its erroring out as below:
`create or replace procedure testsproc()
RETURNS VARCHAR
language sql
as
$$
BEGIN
SELECT * FROM non_existent_table;
EXCEPTION
WHEN OTHER THEN
LET LINE := SQLCODE || ': ' || SQLERRM;
INSERT INTO myexception VALUES (:LINE); -- this line works
call SYSTEM$SEND_EMAIL('MYEMAIL','abc@mail.com','Errors!!',LINE); -- this line is throwing the error invalid identifier 'LINE' (line 320)
return line;
END;
$$`
I tried passing :LINE to system$send_email, it still isn’t working. What am I doing wrong?
Any help is much appreciated.
>Solution :
It’s missing a colon, the same colon the script uses in the previous line:
Fixed:
call SYSTEM$SEND_EMAIL('MYEMAIL','abc@mail.com','Errors!!', :LINE);
With that, I get the desired exception in my email:
