pg中使用游标进行base64解码
1.原数据中compvalue_nocomp字段为base64编码,需进行base64解码;
2.采用游标进行操作,更新每条数据。
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; $$