Postgre數據庫自定義函數


                                                                                                              自定函數

1、查詢函數:

    

 select prosrc from pg_proc where proname='test'

參數說明 : test 為函數名。

 

2、刪除函數:

     

1  drop function test(anyelement,anyelement,numeric)

 參數說明 : test 為函數名。

 

3、定義數據庫函數: 

 

1  create or replace function calculate_speed(end_time anyelement,begin_time anyelement,length numeric) RETURNS numeric  as
2   $$
3      declare
4      total_second numeric;
5      begin
6             select extract(epoch from((end_time::timestamp - begin_time)))/3.6 into total_second;
7             return round(length::numeric/total_second::numeric,3);
8  end;
9   $$ LANGUAGE plpgsql;

 參數說明:calculate_speed代表自定義函數名稱     anyelement numeric參數類型   begin end函數體的開始和結束


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM