pg中使用游标进行base64解码

发布时间 2023-05-05 16:55:39作者: 叶不知秋归来

1.

 

DO $$
DECLARE 
    rec_compvalue RECORD;
    cur_compvalue CURSOR
       FOR SELECT *
       from t_compvalue 
       where compvalue_nocomp like 'Wyk%';
BEGIN
   -- Open the cursor
   OPEN cur_compvalue;
   
   LOOP
    -- fetch row into the film
      FETCH cur_compvalue INTO rec_compvalue;
    -- exit when no more row to fetch
      EXIT WHEN NOT FOUND;
      UPDATE t_compvalue SET compvalue_nocomp=convert_from(decode(compvalue_nocomp,'base64'),'UTF8')
      WHERE CURRENT OF cur_compvalue;      

      RAISE NOTICE 'Output: %',rec_compvalue.compvalue_nocomp;
   END LOOP;
  
   -- Close the cursor
   CLOSE cur_compvalue;
 
END; $$
View Code