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

  • Home
  • SEARCH
  • 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 6827619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:17:12+00:00 2026-05-26T22:17:12+00:00

I’m trying to return a result set from a 11g Oracle table, after I’ve

  • 0

I’m trying to return a result set from a 11g Oracle table, after I’ve received the set back I need to set all the fetched rows as updated.

The below script returns only one row at a time, and I can’t really get the update to work as I like. Some basic explanation would be highly appriciated.

Maybe it’s also a bad idea using the rowtype?

CREATE OR REPLACE PROCEDURE OWNER_EXT.X_GETEXTERNALACCOUNTREF(result out X_externalaccountref%rowtype)
 IS
    cur SYS_REFCURSOR;

 BEGIN

 open cur for select * from X_externalaccountref WHERE externalstatus IS NULL;


  LOOP
   FETCH cur INTO result;

   update X_externalaccountref set  externalstatus = 1, externalchangedate = SYSDATE() where X_id = result.X_id; 

   EXIT WHEN cur%NOTFOUND;
  END LOOP;

  close cur;

 END;
/
  • 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-05-26T22:17:13+00:00Added an answer on May 26, 2026 at 10:17 pm

    Why you only get one record returned:
    You loop over the recordset, fetching one record at a time, and each time you assign this record to the output variable. So only your last record will be stored in the output variable.

    What you want to do is return a record set. For this, you can use pl/sql tables. To easily fetch a set into a table you could use bulk collect into (a link – but google will find you a lot more). You can use the rowtype as the type for your table, or a type you make up yourself. You could use a package variable to declare a type, or define a type in the database schema. If you use rowtype, that is not bad at all. If your table should change, then rowtype will reflect this aswell, saving you the hassle of trawling through your code to add or remove columns should you have manually declared each column in a own type.

    Ex:

    function hand_out_money
    return pck_emp.t_tab_emp
    is
       tab_emp pck_emp.t_tab_emp;
    begin
       select *
         bulk collect into tab_emp
         from emp
        where deptno = 20;
    
       update emp 
          set comm = comm + 10 
        where deptno = 20;
    
       return tab_emp;
    end;
    

    To be able to use this, have t_tab_emp declared in a package_spec. This way, you can reference the returned type from where you call this code. Just put type t_tab_emp is table of emp%rowtype; in there – like i would do in package pck_emp.

    Your calling code could then be:

    declare
       tab_result pck.t_tab_emp;
    begin
       tab_result := hand_out_money;
    end;
    

    To do your update:
    If you fetch all your record into a plsql table, you could thereafter do a single update statement:

    update X_externalaccountref 
       set externalstatus = 1, externalchangedate = SYSDATE
     where externalstatus IS NULL;
    

    Also: you could just use a function if you only return this one variable, it would make sense for a getter.

    Also: i generally don’t like function or procedures named ‘getxxx’ who then do DML. More proper would be to call your procedure ‘activate_external_accounts’ for example, which would then return the recordset. Mind, that if you do a bulk select before the update, the externalstatus and externalchangedate won’t be updated! So you don’t get a resultset returned, but a pre-update set.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters

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.