当前位置:网站首页>Implementation of decode function in GP

Implementation of decode function in GP

2022-06-21 17:20:00 MyySophia

oracle There is one of them. decodde function , The students like it very much . from Oracle Migrate to GP when , If there is decode , There will be fewer code changes

The following is a GP Of decode Realization

create or replace function pg_catalog.decode(variadic p_decode_list text[])
returns text as
$$
declare
 v_len integer := array_length(p_decode_list, 1);
 v_ret text;
begin
 if v_len >= 3 then
  for i in 2..(v_len - 1) loop
   v_ret := null;
   if mod(i, 2) = 0 then
    if p_decode_list[1] = p_decode_list[i] then
     v_ret := p_decode_list[i+1];
    elsif p_decode_list[1] <> p_decode_list[i] then
     if v_len = i + 2 and v_len > 3 then
      v_ret := p_decode_list[v_len];
     end if;
    end if;
   end if;
   exit when v_ret is not null;
  end loop;
 else
  raise exception 'UPG-00938: not enough args for function.';
 end if;
 return v_ret;
end;
$$
 language plpgsql;

原网站

版权声明
本文为[MyySophia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211331576128.html