fetch from function returning a ref cursor to record

后端 未结 3 623
长发绾君心
长发绾君心 2021-01-19 18:30

I have a function in a package that returns a REF CURSOR to a RECORD. I am trying to call this function from a code block. The calling code looks like this:

         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-19 18:58

    I suspect that you think that your cursor should be fetching rows from the REFCURSOR. It's not. The REFCURSOR is itself a cursor, you don't use another cursor to select from it.

    What your current cursor is doing is fetching a single row, with a single column, containing the result of the function call. Which is a record_cursor not a record_name, so you get a type mismatch.

    I suspect what you really want to do is something like this:

    declare
      symbol_cursor  package_name.record_cursor;
      symbol_record  package_name.record_name;
    begin
      symbol_cursor := package_name.function_name('argument');
      loop
        fetch symbol_cursor into symbol_record;
        exit when symbol_cursor%notfound;
    
        -- Do something with each record here, e.g.:
        dbms_output.put_line( symbol_record.field_a );
    
      end loop;
    
      CLOSE symbol_cursor;
    
    end;
    

提交回复
热议问题