虽然postgresql中的功能不起作用

时间:2014-07-11 03:44:26

标签: c++ sql postgresql

我有3个表,tblAnalyse,tblSubAnalyse,tblResault

tblAnalyse: id整数, 姓名文字, isParent bool,

tblSubAnalyse: id整数, analyseId整数, 姓名文字,

tblResault: id整数, analyseId整数, subAnaliseId整数, accountId整数, 分析日期,

好的,现在当表tblAnalyse中的isParent为True时我想将subAnalysis插入到result中,我写了Function但是它确实没有工作

CREATE OR REPLACE FUNCTION year_2014.insertsubanalysis
(
  accountid      integer,
  analyseid      integer,
  analysedate    date,
  requestnumber  integer
)
RETURNS record AS
$$
DECLARE 
i INTEGER;
AnalyseCount INTEGER;
SubAnalyseId INTEGER;
begin
i := 1;
SELECT public."SubAnalyze".id into SubAnalyseId FROM  public."SubAnalyze" where public."SubAnalyze".analyze_id = analyseid;
SELECT count(public."SubAnalyze".id) into AnalyseCount FROM  public."SubAnalyze" where public."SubAnalyze".analyze_id = analyseid;
WHILE(i <= AnalyseCount) loop
   INSERT INTO year_2014."Results"(account_id, analyze_id, "date", subanalyze_id, requestnumber)
VALUES
    (accountid, analyseid, 'analysedate', SubAnalyseId, requestnumber);
END LOOP;
RETURN 1; 
end
$$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;

ALTER FUNCTION year_2014.insertsubanalysis(accountid integer, analyseid integer, analysedate date, requestnumber integer)
OWNER TO postgres;

1 个答案:

答案 0 :(得分:0)

当我运行该功能时:

SQL错误:错误:返回的函数需要列定义列表&#34;记录&#34; 第1行:SELECT * FROM year_2014.insertsubanalysis(7,14,&#39; 12/12/2014 ...                       ^