oracle - Using %TYPE on a record field in PL/SQL -


This is making me crazy for a while:

  DECLARE TYPE AttrValueRec is RECORD (Atter VARCHAR2 (40), Val VARCHAR2 (2000), Insta Number (4)); Functions create_attrval (attr AttrValueRec.attr% TYPE, Val AttrValueRec.val% TYPE, Inst AttValueRec.inst% TYPE: = 1) Return AttrValueRec attr_value AttrValueRec; BEGIN attr_value.attr: = attr; Attr_value.val: = val; Attr_value.inst: = inst; Back attr_value; End; BEGIN tap; End;  

Using % TYPE on a record field does not work. This generates the following error:

  ORA-0650: line 8, column 36: PLS-00206:% should be applied on a type, column, area or feature, not " ATTRVALUEREC ATTR "ORA-0650: Line 8, Column 5: PL / SQL: Ignore Item  

Clearly works again when defining type:

  DECLARE TYPE AttrValueRec is the record (Atir VARCHAR2 (40), Val VARCHAR2 (2000), Instance Number (4)); Functions create_attrval (etir VARCHAR2, VALAR VARCHAR2, inst NUMBER: = 1) return ATOLAR ARTR_EView attributeRAC; BEGIN attr_value.attr: = attr; Attr_value.val: = val; Attr_value.inst: = inst; Back attr_value; End; BEGIN tap; End;  

Can anyone explain to me why does not this work?

Thank you.

look% TYPE and% ROWTYPE - reference only the database column But you try to refer to the user type.

The solution defines your pl / sql type with a% TYPE-referer on a database column, and then creates a function with the parameter that references the same database column. / P>

UPDATE

It does not have the full truth because the lead commentator posts useful ideas. Summary% TYPE and% ROWTYPE can not only mention table columns. Look at the "real" objects as the variables and cursors are good.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -