create type. pls 00363 expression cannot be used as an assignment

4.2k views Asked by At

help me please to understand this error.. May be i must do ud_mosh_dvig(x number, y number) and create type body after.

create or replace type CAR as object
(
 mosh_dvig number,
 obiem_dvig number,
 color varchar2(20),
 type_form varchar2(20),
 massa number,
 num_peredach number,
 ud_mosh number,
 member function ud_mosh_dvig return number
);

create or replace type body CAR
is
member function ud_mosh_dvig return number
as
begin 
 self.ud_mosh:=self.mosh_dvig/self.massa;
 return self.ud_mosh;
end ud_mosh_dvig;
end;
1

There are 1 answers

0
Nick Krasnov On BEST ANSWER

By default, for every non-static function, implicitly declared self parameter is in IN parameter mode. It means, that it simply cannot be modified. But, it should be noted that for non-static procedures self parameter is in IN OUT default parameter mode.

Although it is not a good practice to allow a function to return multiple values, change value ud_mosh property of an object and return the same value to the invoker, in this case, you can explicitly declare self parameter of the function in IN OUT parameter mode:

create or replace type CAR as object (
  mosh_dvig    number,
  obiem_dvig   number,
  color        varchar2(20),
  type_form    varchar2(20),
  massa        number,
  num_peredach number,
  ud_mosh      number,
  member function ud_mosh_dvig(self in out car) return number
);

TYPE CAR compiled

create or replace type body CAR
is
  member function ud_mosh_dvig(self in out car) 
  return number as
  begin 
    self.ud_mosh := self.mosh_dvig/self.massa;
    return self.ud_mosh;
  end ud_mosh_dvig;
end;

TYPE BODY CAR compiled

But you wont be able to use that function in SQL, because of declared formal parameter of the function in IN OUT parameter mode - only PL/SQL

set serveroutput on;
clear screen;
declare
  l_obj  car;
  l_obj1 car;
  l_res number;
begin
  l_obj := new car(1,1,'1','1',4,1,1);
  l_res := l_obj.ud_mosh_dvig();
  dbms_output.put_line('ud_mosh prop value: ' || l_obj.ud_mosh || chr(13) 
                       || 'Function returns: ' || to_char(l_res));
end; 
/

anonymous block completed

ud_mosh prop value: 0.25
Function returns:   0.25