DB2中的存儲過程和函數
這個DB2快把人折騰死了,楞是不知道函數和存儲過程是怎么寫的。今天弄了一個多小時寫了一個函數,趕快記下來:DROP FUNCTION?myfunction;
CREATE FUNCTION?myfunction(idvalue int) returns varchar(10)
language sql
specific myfunction
? f:begin atomic --注意這個關鍵字: the body of the function is wrapped with BEGIN ATOMIC
??? declare v_id int;
??? declare v_name char(7);
??? set (v_id,v_name) = (
????? select id,name
??????? from test
??????? where id = idvalue);
??? return v_name||char(v_id);
? end f;
NND,不知道是我機器環境的問題,還是DB2太變態:在執行table function時,一定要賦予一個別名么?
select * from table(mytabfunc2(1)) as b --竟然不要都不行!!!
DB2 江湖黑話:UDF-User-Defined Functions
??????????????????????????????LUW-Linux 、Unix、Windows