pgsql字符串转数组,转json等


 

do $$
declare 
    str text :='{ 
      "tzmxList": [ 
          { 
              "ZCPH": "CPH000000001", 
              "CPID": "1111", 
              "SYJB": "11",
              "TZJE": "1000000" 
          }, 
          { 
              "ZCPH": "CPH000000002", 
              "CPID": "2222", 
              "SYJB": "22",
              "TZJE": "2000000"  
          }, 
          { 
              "ZCPH": "CPH000000003", 
              "CPID": "3333", 
              "SYJB": "33",
              "TZJE": "3000000" 
          } 
      ] 
  }';
	note varchar;
	paramlist jsonb;
	tzmxList jsonb;
	code int;
	rec jsonb;

	V_ZCPH     varchar(20);        -- 子产品账号
	V_CPID     integer;            -- 投资产品
	V_SYJB     integer;            -- 受益级别
	V_TZJE     decimal(20,2);      -- 投资金额
begin
   paramlist := str;
   if paramlist ? 'tzmxList' then
       tzmxList := paramlist->'tzmxList';
	   code := jsonb_array_length(tzmxList);
       raise notice 'exists:count=%,%',code,tzmxList;
	   for rec in select value from jsonb_array_elements(tzmxList)
	   loop
	   	  V_ZCPH := rec->>'ZCPH';  --获取 子产品账号
		  V_CPID := rec->>'CPID';  --获取 投资产品
		  V_SYJB := rec->>'SYJB';  --获取 受益级别
		  V_TZJE := rec->>'TZJE';  --获取 投资金额	
		  raise notice 'exists:count=%,%,%,%',V_ZCPH,V_CPID,V_SYJB,V_TZJE;
	  end loop;  
   else 
       raise notice 'not exists';
   end if;
end
$$;

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM