Home » SQL & PL/SQL » SQL & PL/SQL » How to I execute a function inside a package
How to I execute a function inside a package [message #36954] Mon, 07 January 2002 09:29 Go to next message
paru
Messages: 4
Registered: January 2002
Junior Member
Hello,

I have the following package created. How do I execute the function inside the package.

CREATE OR REPLACE PACKAGE GFH_UPDATE_TO
as
function Update_GFH_TO ( nDataType IN Number,
nSeqNo IN Number,
iState IN Number,
iCommit IN number default 1 )
return number;
END GFH_UPDATE_TO;
/

CREATE OR REPLACE PACKAGE BODY GFH_UPDATE_TO
as
function Update_GFH_TO ( nDataType IN Number,
nSeqNo IN Number,
iState IN Number,
iCommit IN number default 1 ) return number
is
begin
update GFH_TRANSPORT_ORDER
SET state=iState,
timestamp=SYSDATE
where seqno=nSeqno;
end;
/

Please help.
Thanks,
Paru
Re: How to I execute a function inside a package [message #36961 is a reply to message #36954] Mon, 07 January 2002 10:43 Go to previous message
Jon
Messages: 483
Registered: May 2001
Senior Member
Did this even compile? It shouldn't have. For starters, it isn't a function. You say in the signature that you're returning a number, but do you? I don't think so. So it should probably be a procedure. Secondly, in the body, you want to "end;" your function (or procedure) and then "end;" your body. Finally, you don't want a package that is so closely tied to only one procedure.

All that said, here is something that will work:

15:39:59 ==> CREATE OR REPLACE PACKAGE GFH_UPDATE_TO
15:40:00 2 as
15:40:00 3 procedure Update_GFH_TO ( nDataType IN Number,
15:40:00 4 nSeqNo IN Number,
15:40:00 5 iState IN Number,
15:40:00 6 iCommit IN number default 1 );
15:40:00 7 END GFH_UPDATE_TO;
15:40:00 8 /

Package created.

15:40:01 ==> CREATE OR REPLACE PACKAGE BODY GFH_UPDATE_TO
15:40:01 2 as
15:40:01 3 procedure Update_GFH_TO ( nDataType IN Number,
15:40:01 4 nSeqNo IN Number,
15:40:01 5 iState IN Number,
15:40:01 6 iCommit IN number default 1 )
15:40:01 7 is
15:40:01 8 begin
15:40:01 9 update GFH_TRANSPORT_ORDER
15:40:01 10 SET state=iState,
15:40:01 11 timestamp=SYSDATE
15:40:01 12 where seqno=nSeqno;
15:40:01 13 end;
15:40:01 14 end;
15:40:01 15 /

Package body created.

15:40:02 ==> exec gfh_update_to.update_gfh_to(1,2,3,4);

PL/SQL procedure successfully completed.

15:40:24 ==>
Previous Topic: Modified Date and Time of a Row
Next Topic: Multiple Record Sets?
Goto Forum:
  


Current Time: Thu Aug 06 02:58:04 CDT 2020