Home » SQL & PL/SQL » SQL & PL/SQL » Modify Supertype without dropping Subtypes (Oracle 11g)
Modify Supertype without dropping Subtypes [message #597248] Wed, 02 October 2013 01:03 Go to next message
wmgonzalbo
Messages: 98
Registered: November 2008
Member
Hi All,

This might be wishful thinking but is there a way to modify supertypes without dropping / recreating its subtypes?
So far, I can't find any other way to do this.

Thanks in advance!

Regards,
WMG
Re: Modify Supertype without dropping Subtypes [message #597252 is a reply to message #597248] Wed, 02 October 2013 02:49 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Hello,

I don't understand what you mean by dropping subtypes? Types can be defined at schema level, but as far as I know, subtypes are specific to PL/SQL, therefore, at most, there can be defined at a package level.

Anyway, what is exactly the requirement and what are you trying to do? describe your scenario.

Regards,
Dariyoosh

[Updated on: Wed, 02 October 2013 03:03]

Report message to a moderator

Re: Modify Supertype without dropping Subtypes [message #597256 is a reply to message #597252] Wed, 02 October 2013 03:42 Go to previous messageGo to next message
wmgonzalbo
Messages: 98
Registered: November 2008
Member
Supertype sample:

CREATE OBJ_SUPER1 as object
(num1 number,
 num2 number,
 str1 varchar2(100),
 date1 date,
 MEMBER FUNCTION getNum1 RETURN NUMBER,
 MEMBER FUNCTION getStr1 RETURN VARCHAR2,
 MEMBER FUNCTION getDate RETURN DATE
) NOT FINAL;

CREATE TYPE BODY OBJ_SUPER1 AS
-- list supertype methods' body


Subtype sample:

CREATE OBJ_MY_SUB1 UNDER OBJ_SUPER1
(  subnum1 number,
   subnum2 number,
   subdate1 date,
   MEMBER FUNCTION subnum1 RETURN NUMBER,
   MEMBER FUNCTION subdate1 RETURN NUMBER
) NOT FINAL
/

CREATE TYPE BODY OBJ_MY_SUB1 AS
-- list subtype methods' body


Basically your subtype will inherit the attributes and methods of your supertype.

Currently whenever you have to update your supertype (parent), you have to drop its subtypes (children) under it.
A supertype can have several subtypes under it, so currently we are required to drop all children before we can modify the parent.

I'm wondering, if there's a way to modify your supertype without requiring you to drop its subtypes first?
If there is, then how..?
Re: Modify Supertype without dropping Subtypes [message #597258 is a reply to message #597256] Wed, 02 October 2013 04:27 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
If you use ALTER TYPE statement to change the parent type for example to add a new attribute to the parent type, then you can specify CASCADE to propagate the change.

SQL> CREATE TYPE parentType AS OBJECT
  2  (
  3      parentAttr1 NUMBER
  4  ) NOT FINAL;
  5  /

Type created.

SQL> SHOW ERRORS;
No errors.
SQL> 
SQL> CREATE TYPE childType UNDER parentType
  2  (
  3      childAttr DATE
  4  );
  5  /

Type created.

SQL> SHOW ERRORS;
No errors.
SQL> 
SQL> ALTER TYPE parentType ADD ATTRIBUTE parentAttr2 NUMBER CASCADE;

Type altered.

SQL> SHOW ERRORS;
No errors.
SQL> 
SQL> 
SQL> DESCRIBE childType;
 childType extends TRAINING.PARENTTYPE
 Name					   Null?    Type
 ----------------------------------------- -------- ----------------------------
 PARENTATTR1					    NUMBER
 PARENTATTR2					    NUMBER
 CHILDATTR					    DATE

SQL> 


For more information about the restrictions, you can refer to ALTER TYPE statement

Regards,
Dariyoosh
Re: Modify Supertype without dropping Subtypes [message #597260 is a reply to message #597258] Wed, 02 October 2013 04:37 Go to previous messageGo to next message
wmgonzalbo
Messages: 98
Registered: November 2008
Member
^ Thank you for the reply! I guess we can add, drop and recompile but not specifically update the logic inside a supertype's method then.
Re: Modify Supertype without dropping Subtypes [message #597261 is a reply to message #597260] Wed, 02 October 2013 04:45 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Well, that was just an example that I gave, you said we want to UPDATE the parent type without giving detail about changing what exactly (attribute, method, ...), that's why I provided the link to ALTER TYPE statement to see all related restrictions about this.

Regards,
Dariyoosh
Re: Modify Supertype without dropping Subtypes [message #597262 is a reply to message #597261] Wed, 02 October 2013 04:50 Go to previous message
wmgonzalbo
Messages: 98
Registered: November 2008
Member
^Understood, but still it helps, thank you.
Previous Topic: after/every 5 rows print the string "execute;" in output [SQL generates batch]
Next Topic: Executing a function from a string variable
Goto Forum:
  


Current Time: Fri Apr 19 07:13:40 CDT 2024