fetch from function returning a ref cursor to record

血红的双手。 提交于 2019-12-01 20:07:46

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;

The function returns a record_cursor, so I would expect a_record should also be a record_cursor. However, it is not clear why you are returning a ref cursor anyway - why can't the function return a record_name type instead?

The pl/sql block to read out the ref cursor looks a bit strange to me. Oracle might not be able to match the type of your cursor c_symbols with the type package_name.record_cursor.

Suggestion:

  • change the declaration of c_symbols to "c_symbols package_name.record_cursor"
  • replace the statement "open c_symbols" with "c_symbols := package_name.function_name('argument')"

As long as the called function really does return a cursor, that should work. Else, you might want to post actual source code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!