title: PLSQL Oracle Cursor in procedure
body: <p>currently I am learning PLSQL, using Oracle. I am trying to get data which will be older than PARAM days decalred in another table. I want the procedure to take all the data, check if some records are older (recv_date) than parameter from param_value and if yes than fire my alarm procedure. I have problem with declaring a CURSOR and ln_pallets_container. I know I could somehow get into ln_pallets data only WHERE the recv_date I already filtered but neither here I have no idea how to do it correctly. Maybe I should declare cursor before procedure and not inside of it?</p>
  
  <pre><code>  procedure CHECK_STOCK_DATE(warehouse_id_in IN warehouse.warehouse_id%TYPE)
  IS
  ln_pallet_count NUMBER;
  ln_days_till_expiration param_value.param_value%TYPE;
  
  CURSOR ln_pallets IS
         SELECT container_id, recv_date
         FROM wms_stock ws
  
  ln_pallets_container%ROWTYPE;
  
  
  BEGIN
  
         OPEN ln_pallets;
              LOOP
                  FETCH ln_pallets INTO ln_pallets_container;
                  EXIT WHEN ln_pallets%NOTFOUND;
  
                  SELECT param_value.param_value
                  INTO ln_days_till_expiration
                  FROM param_value
                  WHERE param_value.parameter_id = 266;
  
                     IF(ln_pallets_container.recv_date &gt;= trunc(sysdate - ln_days_till_expiration)
  
                        ALARM.ALARM(WAREHOUSE_ID =&gt;MY_COMMONS.GET_WHRS_ID,
  SOURCE_TEXT =&gt; ln_pallets_container.container_id,
  MESSAGE_CODE =&gt; 'Cannot find this container on warehouse. Check container code.');
                    END IF;
              END LOOP;
          CLOSE ln_pallets;
  END;
  </code></pre>