title: How to return a value from a stored procedure (not function)?
body: <p>I have a Stored Procedure that inserts, updates or deletes tablerows. It was working fine while all parameters were used as input. However, I need to return the ID of last inserted row. For that I tried using an <code>INOUT</code> parameter and <code>RETURNING</code> after the <code>INSERT</code> statement to return the ID.</p>
  <p>However, I am not sure how to bind the returned ID to the <code>INOUT</code> parameter. Following is the code for stored procedure:</p>
  <pre><code>CREATE OR REPLACE PROCEDURE public.spproductinsertupdatedelete(
  _ser integer,
  _subcategid integer,
  _inrprice numeric,
  _usdprice numeric,
  _colour integer,
  _size integer,
  _qty integer,
  _prodid integer DEFAULT NULL::integer,
  inout _pid integer default null
   )
  LANGUAGE 'plpgsql'
  AS $BODY$
  
  BEGIN
    if _ser=1 then --- Insert
      INSERT INTO product (prod_subcateg_id,prod_inr_price,prod_usd_price,prod_colour,prod_size,prod_qty)
      VALUES (_subcategID, _inrprice, _usdprice, _colour, _size, _qty)
      RETURNING prod_id;
  
  ELSEIF _ser=2 THEN
      
      UPDATE PRODUCT SET
      prod_subcateg_id = _subcategid,
      prod_inr_price = _inrprice,
      prod_usd_price = _usdprice,
      prod_size = _size,
      prod_colour = _colour,
      prod_qty=_qty
      where prod_id = _prodID;
  
  ELSEIF _ser=3 THEN ---- Delete
      UPDATE PRODUCT SET prod_datetill = now()
      WHERE prod_id = _prodID;
      
  end if;
  
  END
  $BODY$;
  </code></pre>
  <p>On executing above stored procedure, I receive this error:</p>
  <blockquote>
  <pre><code>ERROR:  query has no destination for result data
  </code></pre>
  </blockquote>