简体   繁体   中英

how can I create a stored procedure sql workbench that uses a redshift database?

is it possible to create a stored procedures on sql workbench that uses a redshift database?

I tried to put in some procedure found on the internet like this one

CREATE OR REPLACE FUNCTION proc_sample RETURN INTEGER
IS
  l_result INTEGER;
BEGIN
  SELECT max(col1) INTO l_result FROM sometable;
  RETURN l_result;
END;

but I get an error the cursor is not located inside a statement

help please.

Here is my translation of your stored procedure for Redshift:

CREATE OR REPLACE PROCEDURE proc_sample (
      l_result  OUT  INTEGER
)
LANGUAGE plpgsql
AS $$
BEGIN
  SELECT max(col1) INTO l_result FROM sometable;
END
$$;

You call this stored procedure in Redshift as follows:

BEGIN; CALL proc_sample(); END;
--  l_result
-- ----------
--        99

For more information see "Overview of stored procedures in Amazon Redshift"

you can not use from clause in function. you have to use procedure having parameter with out clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM