dbTalk Databases Forums  

How to pass a record to a Procedure

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss How to pass a record to a Procedure in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Keith
 
Posts: n/a

Default How to pass a record to a Procedure - 11-16-2004 , 02:06 PM






I have a very large program (2000+ lines) and I want to try to break
it down into smaller pieces, make it more modular. I have a cursor
with 80 fields. While in the cursor loop, I want to call a procedure
and pass the whole cursor record. It will do some processing on the
record and then return the record to the calling procedure so that the
updated values can be used. How can I do this?

....Thanks

For Example:

CREATE OR REPLACE PROCEDURE proc1
IS
v_result NUMBER;
CURSOR emp_cursor
IS
SELECT * FROM rmp_table;

BEGIN
FOR emp_rec IN emp_cursor LOOP
IF emp_rec.termination_date > '01-jan-2004 THEN
proc2(emp_rec, v_result);
END IF;
IF v_result > 0 THEN
DBMS_OUTPUT.PUT_LINE(emp_rec.emp_no || ',' || emp_rec.last_name
....
END IF;
NEXT;
END;
/

PROCEDURE proc2(emp_rec IN OUT SomeTpyeOfRec, v_result OUT NUMBER)
IS
BEGIN
IF emp_rec.pension_type = 'DC' THEN
emp_rec.pension_type := 'Defined Contribution';
v_result := v_result + 1;
END IF;
IF emp_rec.ins_type = '1x' THEN
emp_rec.ins_type := 'One Times Salary';
v_result := v_result + 1;
END IF;
etc...
END;
/

Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: How to pass a record to a Procedure - 11-18-2004 , 12:15 AM






Keith wrote:

Quote:
I have a very large program (2000+ lines) and I want to try to break
it down into smaller pieces, make it more modular. I have a cursor
with 80 fields. While in the cursor loop, I want to call a procedure
and pass the whole cursor record. It will do some processing on the
record and then return the record to the calling procedure so that the
updated values can be used. How can I do this?

...Thanks

For Example:

CREATE OR REPLACE PROCEDURE proc1
IS
v_result NUMBER;
CURSOR emp_cursor
IS
SELECT * FROM rmp_table;

BEGIN
FOR emp_rec IN emp_cursor LOOP
IF emp_rec.termination_date > '01-jan-2004 THEN
proc2(emp_rec, v_result);
END IF;
IF v_result > 0 THEN
DBMS_OUTPUT.PUT_LINE(emp_rec.emp_no || ',' || emp_rec.last_name
...
END IF;
NEXT;
END;
/

PROCEDURE proc2(emp_rec IN OUT SomeTpyeOfRec, v_result OUT NUMBER)
IS
BEGIN
IF emp_rec.pension_type = 'DC' THEN
emp_rec.pension_type := 'Defined Contribution';
v_result := v_result + 1;
END IF;
IF emp_rec.ins_type = '1x' THEN
emp_rec.ins_type := 'One Times Salary';
v_result := v_result + 1;
END IF;
etc...
END;
/
Turn it into a package.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond)


Reply With Quote
  #3  
Old   
Watson Davis
 
Posts: n/a

Default Re: How to pass a record to a Procedure - 12-02-2004 , 01:00 AM



keith_newsg (AT) yahoo (DOT) ca (Keith) wrote in news:f1c2be54.0411161206.457669c6
@posting.google.com:

Quote:
I have a very large program (2000+ lines) and I want to try to break
it down into smaller pieces, make it more modular. I have a cursor
with 80 fields. While in the cursor loop, I want to call a procedure
and pass the whole cursor record. It will do some processing on the
record and then return the record to the calling procedure so that the
updated values can be used. How can I do this?
There are several ways you can do this. Keeping your code just the way it
is, just replace your SomeTpyeOfRec with rmp_table%type.

You could also package this and pull the cursor declaration outside of
proc1, and then replace SomeTpyeOfRec with emp_cursor%type.

Watson (the pencil neck) Davis


Reply With Quote
  #4  
Old   
Patrick van Zweden
 
Posts: n/a

Default Re: How to pass a record to a Procedure - 12-14-2004 , 04:18 AM



On 16 Nov 2004 12:06:45 -0800, Keith wrote:

Quote:
I have a very large program (2000+ lines) and I want to try to break
it down into smaller pieces, make it more modular. I have a cursor
with 80 fields. While in the cursor loop, I want to call a procedure
and pass the whole cursor record. It will do some processing on the
record and then return the record to the calling procedure so that the
updated values can be used. How can I do this?

Use a procedure that takes a %rowtype of the cursor and modifies that.
Sample procedure:

CREATE PROCEDURE xx_patrick_modproc(p_row IN OUT xx_patrick_test%ROWTYPE)
AS
BEGIN
p_row.name := 'modified';
END;

xx_patrick_test is a small table, but also could be a cursor consisting of
just one attribute (name).

You call it like this:

declare
begin
for rec1 in (select * from xx_patrick_test) loop
dbms_output.put_line('Before:'||rec1.name);
xx_patrick_modproc(rec1);
dbms_output.put_line('After:'||rec1.name)
end loop;
end;

Anyway you might already found an answer, because i realize this thread is
already almost a month old. Anyway, should have realized before starting to
type

Patrick


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.