Home » SQL & PL/SQL » SQL & PL/SQL » Record Compatability
Record Compatability [message #348183] Mon, 15 September 2008 23:07 Go to next message
ramya29p
Messages: 100
Registered: November 2007
Location: Chennai
Senior Member
Hi,The following code is giving error.... can any one give me the solution

DECLARE
   TYPE name_type1 IS RECORD
      (first_name VARCHAR2(15),
       last_name VARCHAR2(30));

   TYPE name_type2 IS RECORD
      (first_name VARCHAR2(15),
       last_name VARCHAR2(30));

   name_rec1 name_type1;
   name_rec2 name_type2;
BEGIN
   name_rec1.first_name := 'John';
   name_rec1.last_name  := 'Smith';
   name_rec2 := name_rec1; -- illegal assignment
END;

Re: Record Compatability [message #348184 is a reply to message #348183] Mon, 15 September 2008 23:10 Go to previous messageGo to next message
BlackSwan
Messages: 25037
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/t/88153/0/
Please read & FOLLOW the Posting Guidelines as stated in URL above


ERROR? What Error? I don't see any error.

Why do you expect folks to fix a problem they can not see?????
Re: Record Compatability [message #348185 is a reply to message #348184] Mon, 15 September 2008 23:20 Go to previous messageGo to next message
ramya29p
Messages: 100
Registered: November 2007
Location: Chennai
Senior Member
Hi Sorry i missed out the Error Message

DECLARE
   TYPE name_type1 IS RECORD
      (first_name VARCHAR2(15),
       last_name VARCHAR2(30));

   TYPE name_type2 IS RECORD
      (first_name VARCHAR2(15),
       last_name VARCHAR2(30));

   name_rec1 name_type1;
   name_rec2 name_type2;
BEGIN
   name_rec1.first_name := 'John';
   name_rec1.last_name  := 'Smith';
   name_rec2 := name_rec1;  
END;

                
ERROR at line 15:
ORA-06550: line 15, column 17:
PLS-00382: expression is of wrong type
ORA-06550: line 15, column 4:
PL/SQL: Statement ignored



Re: Record Compatability [message #348186 is a reply to message #348183] Mon, 15 September 2008 23:23 Go to previous messageGo to next message
milind.khadloya
Messages: 4
Registered: September 2008
Location: India
Junior Member

You can't assign one record type to other directly. Modify your last statement as below

name_rec2.first_name := name_rec1.first_name;
name_rec2.last_name := name_rec1.last_name;
Re: Record Compatability [message #348189 is a reply to message #348186] Mon, 15 September 2008 23:29 Go to previous messageGo to next message
ramya29p
Messages: 100
Registered: November 2007
Location: Chennai
Senior Member
but i am able to assign cursor based recordtype to userdefined record type. thats why i assigned like this
Re: Record Compatability [message #348192 is a reply to message #348183] Mon, 15 September 2008 23:40 Go to previous messageGo to next message
BlackSwan
Messages: 25037
Registered: January 2009
Location: SoCal
Senior Member
>but i am able to assign cursor based recordtype to userdefined record type. thats

If you say so.

>why i assigned like this
Oracle obviously disagrees.
You have been told that what you attempted generates an error.
So you need to do something different; which does not generate error.

Re: Record Compatability [message #348193 is a reply to message #348192] Mon, 15 September 2008 23:46 Go to previous messageGo to next message
ramya29p
Messages: 100
Registered: November 2007
Location: Chennai
Senior Member
I want to know the reason why i am not able to assign the userdefinedrecordtype to another userdefinedrecordtype. thats the reason i am posting in this forum.
Re: Record Compatability [message #348194 is a reply to message #348193] Mon, 15 September 2008 23:50 Go to previous messageGo to next message
BlackSwan
Messages: 25037
Registered: January 2009
Location: SoCal
Senior Member
ramya29p wrote on Mon, 15 September 2008 21:46
I want to know the reason why i am not able to assign the userdefinedrecordtype to another userdefinedrecordtype. thats the reason i am posting in this forum.


The reason is because Oracle does not allow you to do so.
Accept it!
Nobody here can change how Oracle responds.
Re: Record Compatability [message #348230 is a reply to message #348193] Tue, 16 September 2008 02:48 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Because Oracle sees the two records types as different. You an I can see that they have the same structure, but what Oracle knows is that they are two different types, and it has no way of mapping the columns from type1 onto type2.

We get used to fairly loose typing using pl/sql, and most poeple will happily assign a numeric value to a varchar2 without thinking about it.
Behind the scenes however, this only works because Oracle knows that if you wrap the number in an implicit call to To_Char, then the output of that is allowd to be put into a Varchar2.

In this case, Oracle has no idea what to do, so it raises an exception.
Previous Topic: PLS-00201 Error
Next Topic: Hints for Date Range
Goto Forum:
  


Current Time: Mon Dec 05 07:11:29 CST 2016

Total time taken to generate the page: 0.12519 seconds