DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 14th, 2005, 09:54 AM
jodders2001 jodders2001 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 61 jodders2001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 sec
Reputation Power: 0
probably a really simple question, but...

I'm very new to using db2, and am trying to do the following:
write a script to create a type named persontype, then a typed table named person of that type, then 2 sub-table student and employee which have extra attributes... i think the code below is somewhere close but i don't really understand what should be put in the red parts and why... can anyone shed some light? Ta


CREATE TYPE PERSONTYPE AS
( NAME VARCHAR(40),
BIRTHYEAR INTEGER

)
REF USING INTEGER
INSTANTIABLE
NOT FINAL
MODE DB2SQL

CREATE TABLE PERSON OF PERSONTYPE
(REF IS PEOPLE USER GENERATED)

CREATE TYPE STUDENT UNDER PERSONTYPE AS
(DEGREE_SCHEME VARCHAR(20)
)
INSTANTIABLE
NOT FINAL
MODE DB2SQL

CREATE TABLE STUDENT OF STUDENT
(REF IS PERSON USER GENERATED)

CREATE TYPE EMPLOYEE UNDER PERSONTYPE AS
(SALARY INTEGER)
INSTANTIABLE
NOT FINAL
MODE DB2SQL

CREATE TABLE EMPLOYEE OF PERSONTYPE
(REF IS EMPLOYEE USER GENERATED)

Reply With Quote
  #2  
Old February 27th, 2005, 11:41 PM
paulh1983 paulh1983 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Dec 2004
Posts: 1,249 paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level)paulh1983 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 14 h 18 m 20 sec
Reputation Power: 17
whats the error you get? here is a sample type in oracle! (dont know db2)
Code:
Create or replace Type Person_type as object (
Info	info_type,
address	address_type,
contact	contact_type,

Member function getUserId return Varchar2, 
Pragma Restrict_references(getUserId,wnds,wnps,rnps)
)
INSTANTIABLE NOT FINAL
/

then you need to do this:
Code:
create or replace type body Person_type IS

Member function getUserId return varchar2 IS
	name	varchar2(60);
Begin
	name:=info.UserId ||' '|| info.FName || ' ' || info.LName;
	return name;
End;

END;
/


if you have more methods you put them in my first code after using same context andthen you also put them in the second code using the same thing as i done!


PS> if u r wondering what i am doing here if i dont do DB2 is because i am curious to see the difference between db2/mysql/oracle! lol also i apologise if this isnt any good for you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > probably a really simple question, but...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT