我已經使用 PGADMIN4 創建了一個存盤程序。在 SP 中,我選擇了一個視圖表。但是,我希望將存盤程序中的資料插入到新表中。我試過下面的代碼,但它顯示一個錯誤:
SP 名稱:測驗
新表名:Customer
Insert into public.Customer exec public.Test
這是我的 SP 代碼:
create procedure test()
language plpgsql
as $$
BEGIN
Select * from public.customer_list;
END;
$$;
錯誤:“exec”處或附近的語法錯誤
uj5u.com熱心網友回復:
程序不能在 SQL 中使用。如果您必須有一個存盤程序(定義為存盤在資料庫中要執行的代碼),則更改為 SQL 函式。它回傳一個型別。
create function copy_customer_list()
returns setof customer_list
language sql
as $$
Select * from customer_list;
$$;
然后你可以插入到其他表中
insert into customer
select * from copy_customer_list();
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/321633.html
標籤:PostgreSQL 存储过程
下一篇:CSS--中心元素之間的空隙?
