Search Postgresql Archives

returning ref cursor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please let me know what’s wrong with below code

 

CREATE LANGUAGE plpgsql;

create or replace FUNCTION test_cu( p_cursor REFCURSOR) returns REFCURSOR

   AS $procedure$

BEGIN

   open p_cursor FOR 

   select * from   test;

  

   RETURN p_cursor;

END; $procedure$

LANGUAGE plpgsql;

 

create or replace FUNCTION test_call()

RETURNS VOID

   AS $procedure$

   DECLARE

   c_cursor  REFCURSOR;

   r_emp  test%rowtype;

BEGIN

   PERFORM test_cu(c_cursor);

   loop

      fetch c_cursor into r_emp;

      exit when NOT FOUND;

      RAISE NOTICE '%',r_emp.aaa;

   end loop;

   close c_cursor;

   RETURN;

END; $procedure$

LANGUAGE plpgsql;

 

 

SELECT  test_call();

 

When I execute above code I got below error

 

ERROR:  cursor variable "c_cursor" is null

CONTEXT:  PL/pgSQL function "test_call" line 7 at FETCH

 

********** Error **********

 

ERROR: cursor variable "c_cursor" is null

SQL state: 22004

Context: PL/pgSQL function "test_call" line 7 at FETCH

 

 

Thanks,

Ravi Katkar

 

 

 

 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux