从 DB2 到雪花等价的函数转换

时间:2021-06-16 13:06:25

标签: db2 snowflake-cloud-data-platform

有人可以帮我根据雪花等效转换以下函数吗?

DB2 格式:
CREATE FUNCTION resign_employee (number CHAR(6))
 RETURNS TABLE (empno CHAR(6),
         salary DOUBLE,
         dept  CHAR(3))
-- -------------------------------------------------------------------------------------
-- Purpose: This procedure takes in an employee number, then removes that
--      employee from the EMPLOYEE table.
--      A useful extension to this function would be to archive the
--      original record into an archive table.
-- --------------------------------------------------------------------------------------
  DECLARE l_salary DOUBLE;
  DECLARE l_job CHAR(3);
 
  SET (l_salary, l_job) = (SELECT salary, job
                FROM OLD TABLE (DELETE FROM employee
                        WHERE employee.empno = number));
 
  RETURN VALUES (number,l_salary, l_job);
 END

雪花格式:

create function resign_employee (number VARCHAR(6))
    returns table (empno VARCHAR,salary NUMBER,dept VARCHAR)
    LANGUAGE SQL
    AS
    $$
        'select salary, job from old employee'
        'delete from employee where empno=number'
    $$;

转换后的错误:

Compilation of SQL UDF failed: SQL compilation error: syntax error line 3 at position 8 unexpected ''delete from employee where empno=number''.

0 个答案:

没有答案