function in Postgres

时间:2023-03-10 02:52:21
function in Postgres
CREATE or REPLACE FUNCTION fn_attr_category()
RETURNS void AS
$BODY$
declare
v_tmp_rec record;
begin
--获取待补充品类的规格
for v_tmp_rec in
select * from tcim_s_gcmaster where 'COLOR'||categoryid not in (select attrid from TCim_S_GcAttributeSel) and categoryid like 'L%';
--批量插入明细表
loop
insert into TCim_S_GcAttributeSel
select
replace(selectid, 'L00000V', v_tmp_rec.categoryid),selectname,'COLOR'||v_tmp_rec.categoryid as attrid,'N' as isdefault,seqno
from TCim_S_GcAttributeSel where attrid = 'COLORL00000V';
end loop; end
$BODY$
LANGUAGE 'plpgsql' VOLATILE;