Can't declare variable inside function on PostgreSQL

后端 未结 1 1178
野性不改
野性不改 2021-01-19 05:44

I am writing function in PostgreSQL but it doesn\'t allow me to declare variable inside it. Here is the function.

CREATE FUNCTION clean_emp() RETURNS void AS         


        
相关标签:
1条回答
  • 2021-01-19 06:14

    It is not surprise. The language SQL doesn't support variables. You have to use the language plpgsql.

    CREATE OR REPLACE FUNCTION clean_emp()
    RETURNS void AS $$
    DECLARE cnt varchar;
    BEGIN
    END;
    $$ LANGUAGE plpgsql;
    

    See more in documentation http://www.postgresql.org/docs/current/static/plpgsql.html.

    PostgreSQL has more languages for writing function. The SQL language is perfect for one line single statement macros. The PLpgSQL is classical native language similar to Oracle's PL/SQL with embedded SQL.

    0 讨论(0)
提交回复
热议问题