create or replace function setPassengerType(num varchar) returns varchar as $$ declare sql varchar; str varchar; re record; begin str=''; sql = 'select passenger_type from tops_order.passenger where flight_order_item_id=''' || num ||''''; for re in execute sql loop if str='' then str = re.passenger_type; else str = str ||','|| re.passenger_type; end if; end loop; sql = 'update tops_order.flight_order_item set passenger_type=''' || str ||''' where id=''' || num ||''''; RAISE NOTICE 'i want to print %', sql; execute sql; return str; end $$ language plpgsql; select setPassengerType('140107232230103') --执行存储过程