sql >> Base de Datos >  >> RDS >> Oracle

¿Cómo funcionan los procedimientos almacenados de Oracle (con cursores)?

El procedimiento almacenado está devolviendo algo, simplemente no estás haciendo nada con los resultados.

Puede hacerlo simplemente ejecutando el siguiente script en SQLDeveloper:


VARIABLE csr REFCURSOR;
EXEC getRejectedReasons(:csr); -- the colon identifies the parameter as a variable
PRINT csr;

Otro método es buscar cada fila y hacer algún tipo de procesamiento:


DECLARE
  -- sys_refcursor is weakly typed
  refcsr  SYS_REFCURSOR;
  -- define a record so we can reference the fields
  rej_rec Reasons_for_Rejection%ROWTYPE;
BEGIN

  getRejectedReasons(refcsr);

   -- loop through the results  
   LOOP
      -- gets one row at a time
      FETCH refcsr INTO rej_rec;
      -- if the fetch doesn't find any more rows exit the loop
      EXIT WHEN refcsr%NOTFOUND;
      -- Do something here.  
      -- For example : DBMS_OUTPUT.PUT_LINE(rej_rec.reason_desc);
    END LOOP;

END;