473,545 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usage of TYPE in DB2

4 New Member
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 5399
Neena Paul
4 New Member
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
Neena Paul
4 New Member
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
Neena Paul
4 New Member
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
4120
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 periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string...
1
495
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
6456
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 degradation, including other programs that become unresponsive. Here's what I found while the retrieval process is running: Using the Windows Task...
1
2580
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 breakdowns for as well as one or more customers. Now, the report iterates through the selected items in the finished good listbox. For each item that it...
4
1671
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 sequentially (in the order stored) via "For Each". I know I could code this from scratch - or derived from a number of framework classes, but I'm not sure...
4
5419
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, 21:00:14) 20040728] on freebsd5 Type "help", "copyright", "credits" or "license" for more information. usage:copy source destination
22
3038
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 like that: int main(char argc, char *argv, char *env) { try { auto Exception mainException(1); mainException.setErrNo(42);
9
4172
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 minimize it (all the Forms will Hide, only a NotifyIcon is shown at the System Notification Area), the memory usage comes down to 8MB immediately....
1
8015
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 when that process has gone idle. I put it together this morning because I was tired of starting a program on remote computer, and continuously reconnect...
1
6455
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 ticket. Support ticket is just a GUID that comes along with the exception log at the server side. From WCF programming best practice, What would be...
0
7432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.