在postgres中找不到sql函数

6za6bjd0  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(527)

我想创建一个函数,为学生创建缺勤。如果他有三次缺席,他就会被淘汰。但是在我创建函数之后,当我运行它时,它告诉我找不到它。

CREATE OR REPLACE FUNCTION add_abbssence(
 )
    RETURNS TABLE(  etudiant int , id_matiere int, abssance int) 
    LANGUAGE 'plpgsql'

    COST 100
    VOLATILE 
    ROWS 1000
AS $BODY$

 begin
  return query
 select *   from abssance  order by id_abssance;
        insert into id_abssance (id_etudiant,id_matiere,abssance)
        values (etudiant,matiere ,abssance);
        if abssane = 3 then
            insert into abssance(eliminé)
            values(1);
            --if successful 

            --isnt there 
            end if ;

 end
 $BODY$;

当我运行它时,它告诉我

add_abbssence (integer, integer, integer) does not exist
LINE 1: select * from add_abbssence (66,1,1)
                      ^
HINT: No function corresponds to the given name and to the types of arguments.
You need to add explicit type conversions.
ylamdve6

ylamdve61#

声明的函数没有参数,但在select语句中,函数调用有3个参数:这就是postgresql不调用函数的原因:函数调用数和参数类型必须与函数定义匹配。
新功能代码的工作示例:

create table abssence(id_etudiant int, id_matiere int, abssance int, éliminé int);
    CREATE TABLE

    create or replace function test1(etudiant int, matiere int, abssancee int) 
    RETURNs int as 
    $$ 
    begin 
     insert into abssence(id_etudiant,id_matiere,abssance) values(etudiant,matiere,abssancee); 
    if abssancee=3  
    then 
      insert into abssence(éliminé) values(1); 
      return 1;
    else 
     return 0; 
    end if; 
    end $$ 
    language plpgsql;
    CREATE FUNCTION

    select * from test1(1,2,3);
     test1 
    -------
         1
    (1 row)

相关问题