Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Passing Self as Parameter Or Passing an Object Variable to a member function,Both in IN OUT NOCOPY M

Gaurav RSep 11 2014 — edited Sep 19 2014

Hi All,
Requesting help what approach is better of the two in terms of performance and Why ( if there is any difference ) or are they one and they same and only different in terms of syntax only.

A) To invoke a function with passing self as IN OUT nocopy
B) Passing the same invoking object  as IN OUT NOCOPY.

@
(In My Approach I Have To Pass An Object Having Almost 30 Attributes And I Have To Assign Values To Few Attributes of the object in  few member functions to which object will be passed)

I have an object created as
CREATE OR REPLACE TYPE my_obj AS OBJECT
(
  NAME VARCHAR2(100),
  CONSTRUCTOR FUNCTION my_obj RETURN SELF AS RESULT,
  MEMBER FUNCTION put_name(SELF IN OUT NOCOPY my_obj) RETURN PLS_INTEGER,
  MEMBER FUNCTION insert_name(v_my_obj IN OUT NOCOPY my_obj)   RETURN
PLS_INTEGER,
  MEMBER PROCEDURE get_name
);
/
CREATE OR REPLACE TYPE BODY MY_OBJ IS

  CONSTRUCTOR FUNCTION my_obj RETURN SELF AS RESULT IS
  BEGIN
    NULL;
    RETURN;
  END;

  MEMBER FUNCTION put_name(SELF IN OUT NOCOPY my_obj) RETURN PLS_INTEGER IS
  BEGIN
    self.name := 'my_name_in_self';
    RETURN 1;
  END put_name;

  MEMBER FUNCTION insert_name(v_my_obj IN OUT NOCOPY my_obj)
    RETURN PLS_INTEGER IS
  BEGIN
    v_my_obj.name := 'my_name_in_Alias';
    RETURN 1;
  END insert_name;

  MEMBER PROCEDURE get_name IS
  BEGIN
    dbms_output.put_line(self.name);
  END;
END;
/

a) Stub 1 invoking put_name :

declare
v my_obj := my_obj();
ret_val number;
begin
ret_val:= v.put_name;
v.get_name;
end;

o/p : my_name_in_self

a) Stub 2 invoking insert_name:

declare
v my_obj := my_obj();
ret_val number;
begin
ret_val:= v.insert_name(v);
v.get_name;
end;

o/p : my_name_in_Alias

Which is a better approach to use put_name or to use insert_name function .
I have to manipulate the object when passed to any of the function.

Thanks in Advance,
Regards,
Gaurav R

This post has been answered by gaverill on Sep 12 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2014
Added on Sep 11 2014
5 comments
2,354 views