pgsql存储过程(实例)

pg存储过程 简单示例:


create or replace function select_resource_produrce(IN mprCode text , IN publicationType text , OUT resourceName text ,OUT resourceId int8)
returns record as
$BODY$ 
BEGIN

	if publicationType = '1' then
		  select book_name_cn ,
						 book_id 
       into resourceName,resourceId
          from t_book
         where mpr_code = mprCode;
  end if;

	if publicationType = '2' then
		  select periodical_name_cn ,
						 periodical_id 
       into resourceName,resourceId
          from t_periodical
         where mpr_code = mprCode;
  end if;

	if publicationType = '3' then
		  select newspaper_name_cn ,
						 newspaper_id 
       into resourceName,resourceId
          from t_newspaper
         where mpr_code = mprCode;
  end if;

	if publicationType = '4' then
		  select audio_name_cn ,
						 audio_id 
       into resourceName,resourceId
          from t_audio
         where mpr_code = mprCode;
  end if;

END;
$BODY$
language plpgsql;

SELECT * from select_resource_produrce('0000000226' , '1')

调用  :SELECT * from select_resource_produrce('0000000226' , '1')
 
 

你可能感兴趣的:(sql)