这个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
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