473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Usage of TYPE in DB2

Hi,

I ve a below structured object TYPE in Oracle to calculate the Simple and Compound interest for an amount..

Expand|Select|Wrap|Line Numbers
  1. CREATE TYPE pnr_typ AS OBJECT
  2.    (
  3.         principle NUMBER,
  4.         interest NUMBER,
  5.         year NUMBER,
  6.         MEMBER FUNCTION si RETURN FLOAT,
  7.         MEMBER FUNCTION ci RETURN FLOAT,
  8.         MEMBER FUNCTION prod(invent NUMBER) RETURN NUMBER
  9.    );
  10. /
  11. show err
  12.  
  13. CREATE TYPE BODY pnr_typ IS
  14.  
  15.       MEMBER FUNCTION si RETURN FLOAT IS
  16.        BEGIN
  17.            RETURN (principle*interest*SELF.year)/100;
  18.        END;      MEMBER FUNCTION ci RETURN FLOAT IS
  19.        BEGIN
  20.            RETURN POWER(SELF.principle*(1 + SELF.interest/100), year);
  21.        END;
  22.  
  23.  
  24.       MEMBER FUNCTION prod (invent NUMBER) RETURN NUMBER IS
  25.        BEGIN
  26.            RETURN (year + invent);
  27.        END;
  28.       END;
  29. /
  30. Show err
  31.  
With in the TYPE i define some attributes like principle, interest, year and more member functions like si, ci, prod to access and modify the TYPE attributes.

This TYPE can be used in

* the column definition while creating a column in a table,
* the procedures or Oracle DB objects as an instance

I would like to know if the TYPE (structured) in DB2 can do the same as the above Oracle TYPE.

Thanks,
Neena
Jun 23 '06 #1
3 5389
Hi ,

I ve successfully created the equivalent for the above Oracle TYPE object in DB2 with the below DB2 code snippet ..

Expand|Select|Wrap|Line Numbers
  1. CREATE TYPE s1.pnr_typ AS
  2.        (
  3.        principle INT,
  4.        interest DECIMAL(5, 2),
  5.        year INT
  6.        )
  7.      NOT FINAL
  8.      MODE DB2SQL
  9.        METHOD SI()
  10.        RETURNS FLOAT
  11.        LANGUAGE SQL
  12.        DETERMINISTIC
  13.        CONTAINS SQL
  14.        NO EXTERNAL ACTION,
  15.  
  16.        METHOD CI()
  17.        RETURNS FLOAT
  18.        LANGUAGE SQL
  19.        DETERMINISTIC
  20.        CONTAINS SQL
  21.        NO EXTERNAL ACTION,
  22.  
  23.        METHOD PROD(NUM INT)
  24.        RETURNS INTEGER
  25.        LANGUAGE SQL
  26.        DETERMINISTIC
  27.        CONTAINS SQL
  28.        NO EXTERNAL ACTION
  29. @
  30.  
  31.    CREATE METHOD SI()
  32.      FOR s1.pnr_typ
  33.      RETURN (SELF..principle*SELF..interest*SELF..year)/100
  34. @
  35.  
  36.    CREATE METHOD CI()
  37.      FOR s1.pnr_typ
  38.      RETURN SELF..principle * POWER((1 + SELF..interest/100), SELF..year)
  39. @
  40.  
  41.    CREATE METHOD PROD(NUM INT)
  42.      FOR s1.pnr_typ
  43.      RETURN  NUM+SELF..year
  44. @
I do not have an idea how to use this TYPE in tables or SQL queries or Procedures, could any body help me with some simple eg. using this TYPE.

Thanks,
Neena
Jun 23 '06 #2
Now I am able to create tables with the structured TYPE as a column , insertions and selections of the TYPE columns into and from the table and the method calls in a Select query is working fine now,

Could any one help me with the usage of structured TYPEs within a procedure or function...

I dont know how to initialise the TYPE in a function....

Any help on this would be highly appreciated..

Thanks
Sn
Jun 26 '06 #3
With due respects to the experts here I wonder is this (TYPE)too complex ... i dint find any solution for my problem...

Sn :confused:
Jun 26 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
1
by: j0mbolar | last post by:
given this example: void bar(const char *fmt, ...) { va_list ap; va_start(ap, fmt); baz(fmt, ap); va_end(ap);
4
by: RH | last post by:
Hi, I am building a windows application that has a feature that retrieves a set of records when a button is clicked. When the records are being retrieved I experience a complete system...
1
by: Tim T. | last post by:
I'm currently working on a report to forecast production for finished goods. The user can select one or more items to forecast. In addition, they may select one or more warehouses to view...
4
by: Mark | last post by:
I want to create a collection class that will be strongly typed (store a specific object type), be keyed with a case insensitive string, and be able to access objects stored by index, or...
4
by: jiang.haiyun | last post by:
Hello all, when i import SOAPpy, the python crashed and print out 'usage:copy source destination'. As follows: ############################ haiyun# python Python 2.4.1 (#2, Mar 28 2006,...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
9
by: deerchao | last post by:
I'm developing a WinForms application. It slowly eats up memory, one client reported that it took 200MB or more, and finnaly crashed. I myself noticed it's common to use up 30MB memory, but if I...
1
by: ShadowLocke | last post by:
This is an HTML application that allows you to monitor the CPU Usage (as seen in task manager) for any one task either on the local computer or a remote computer using vbscript. It then alerts you...
1
by: Max2006 | last post by:
Hi, To protect my WCF service boundaries, I assign a unique support ticket to all server side exceptions, log them and send a general FaultException to client that only include the support...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.