postgresql存储过程例子

CREATE OR REPLACE FUNCTION sp_insert_data()  
RETURNS integer AS $total$  
declare  
    total integer;
    i integer := 1;
BEGIN  
   insert into tb_test(name) values('name1');
    
  while i < 1000 loop
   insert into tb_test(name) values('name1');
     i=i+1;
  end loop;

   SELECT count(*) into total FROM tb_test;  
   RETURN total;  
END;  
$total$ LANGUAGE plpgsql;

posted @ 2020-01-14 14:47  slnngk  阅读(472)  评论(0编辑  收藏  举报