Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:53:50+00:00 2026-06-02T17:53:50+00:00

I want to return a cursor from a function, I have read that I

  • 0

I want to return a cursor from a function, I have read that I can use:

return sys_refcursor

And then

open curs for select* from mytable;
return curs;

I tried curs.att := ‘something’ but I get an error

Also read I can do my own type:

 TYPE type IS REF CURSOR RETURN mytable%ROWTYPE;

Then

CURSOR cur IS
    SELECT* FROM mytable;
var cur%ROWTYPE;

BEGIN
OPEN cur;
FETCH cur INTO var;
var.att = 'something';
RETURN var;

This time I didn’t get an error in the assign but in the return statement.

If I changed the var type to my type I couldn’t fetch the value.

I wan’t to edit the cursor, but not the table, how can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:53:52+00:00Added an answer on June 2, 2026 at 5:53 pm

    A cursor is a read-only structure. The only way to change the data that you would fetch from a cursor is to change the SQL statement that is used to open the cursor or to change the data in the underlying table(s).

    While it is possible to return a cursor from one PL/SQL block to another, it is rarely the appropriate architecture. A SYS_REFCURSOR is generally appropriate when you want to return a result to a client application that knows how to use a cursor.

    Do you really want to return a cursor, though? Or do you want to return a record type? The second code snippet you posted appears to be trying to return a record– that’s certainly possible but you would need to declare that the function returns a record rather than a cursor. That is, the RETURN statement in the declaration would need to be RETURN mytable%ROWTYPE rather than RETURN type. For example, if you want to return a record based on the EMP table

    create or replace function get_emp( p_empno in emp.empno%type )
      return emp%rowtype
    is
      l_rec emp%rowtype;
    begin
      select *
        into l_rec
        from emp
       where empno = p_empno;
      l_rec.sal := l_rec.sal + 100;
      return l_rec;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a set of values from function till the point they
i want to return wchar_t frm a function. How can i implement it wchar_t
I created a plsql function and I want to create a cursor and return
I have a database from which I want to query and display only that
I want to return a private field from a remoted object but i get
I want to return ArrayList<HashMap<String,String>> in EL function with three String argument. How to
I want to return an anonymous data retreived from a query in Linq. I
I have made the following code to retrive data from SQLite database. public Cursor
I want to Write a function that returns the Products brought in a given
I want to run this query in Android Application : SELECT field1 FROM table1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.