我正在PgAdmin中创建一个存储过程,以便将数据插入到不同表的表中。我尝试了以下代码,但我被要求返回类型。我需要添加什么?
另外,如何使用此过程将数据从不同的表中插入表中?
CREATE OR REPLACE FUNCTION stager.ProductDimSP
(
cat_name character varying(25) ,
pr_name character varying(40) ,
pr_id character varying(6) ,
disc boolean
) RETURNS NULL ON NULL INPUT AS
$$
BEGIN
INSERT INTO stager."ProductDimTable"
(
category_name, product_name, product_id, discontinued
)
VALUES
(
cat_name, pr_name, pr_id, disc
)
END
$$
LANGUAGE 'plpgsql';
答案 0 :(得分:2)
CREATE OR REPLACE FUNCTION stager.ProductDimSP
(
cat_name character varying(25) ,
pr_name character varying(40) ,
pr_id character varying(6) ,
disc boolean
)
RETURNS VOID -- this defines a function with no return value
AS
$$
BEGIN
INSERT INTO stager."ProductDimTable"
(
category_name, product_name, product_id, discontinued
)
VALUES
(
cat_name, pr_name, pr_id, disc
); -- this semicolon was also missing
END
$$
LANGUAGE plpgsql; -- do not put the language name in quotes