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 7984927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:25:39+00:00 2026-06-04T11:25:39+00:00

I have a procedure that performs some calculations on all records returned by a

  • 0

I have a procedure that performs some calculations on all records returned by a cursor. It looks a bit like this:

PROCEDURE do_calc(id table.id_column%TYPE)
IS
  CURSOR c IS
    SELECT col1, col2, col3
      FROM table
     WHERE ...;
BEGIN
  FOR r IN c LOOP
    -- do some complicated calculations using r.col1, r.col2, r.col3 etc.
  END LOOP;
END;

Now I have the case where I need to perform the exact same calculation on a different set of records that come from a different table. However, these have the same “shape” as in the above in example.

Is it possible to write a procedure that looks like this:

PROCEDURE do_calc2(c some_cursor_type)
IS
BEGIN
  FOR r IN c LOOP
    -- do the calc, knowing we have r.col1, r.col2, r.col3, etc.
  END LOOP;
END;

I know about SYS_REFCURSOR, but I was wondering if it was possible to use the much more convenient FOR ... LOOP syntax and implicit record type.

  • 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-04T11:25:40+00:00Added an answer on June 4, 2026 at 11:25 am

    Create a package.

    Declare your cursor as package variable.

    Use %rowtype to set function parameter type.

    create or replace package test is
      cursor c is select 1 as one, 2 as two from dual;
    
      procedure test1;
      function test2(test_record c%ROWTYPE) return number;
    
    end test;
    
    
    create or replace package body test is
      procedure test1 is    
      begin
        for r in c loop      
          dbms_output.put_line(test2(r));
        end loop;
      end;
    
      function test2(test_record c%ROWTYPE) return number is
        l_summ number;
      begin
        l_summ := test_record.one + test_record.two;
        return l_summ;
      end;
    end test;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that logs some data, how can I call this
If I have a function that performs some procedure and then needs to return
i have a stored procedure that performs a join of TableB to TableA :
I have this procedure that executes another procedure passed by a parameter and its
In my ASP.NET application, i have a procedure that log all exceptions to a
I have some procedure that perform INSERT statement: CREATE OR REPLACE PROCEDURE potok_insert( p_jfplate
I have a stored procedure that performs an update with a try catch block.
I am working on a stored procedure that performs some operations on students in
I have a stored procedure in SQL Server 2000 that performs a search based
I have inherited a stored procedure which performs joins across eight tables, some of

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.