dbTalk Databases Forums  

sum up datatype of table of numbers

comp.database.oracle comp.database.oracle


Discuss sum up datatype of table of numbers in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jeff Chirco
 
Posts: n/a

Default sum up datatype of table of numbers - 12-16-2004 , 12:29 AM






Ok, I have created my own datatype called num_tab as a table of numbers.
And now I am creating a function where I go through in a loop and insert
differnet numbers into this table of numbers through a variable called
v_numtab. At the end of my function I have to sum up all the numbers in
this table/variable. That is what I don't know how to do. Normally it is
easy to do because I know the column name, but with this datatype created I
dont know the column name. Does anybody know how to sum everything up from
it. I was thinking select sum(v_numtab) from dual; But that didn't work.
Any ideas would be appreciated. Thanks. Please email me with ideas.
Please send to both email addresses. Thank again.


Jeff Chirco
jchirco (AT) adelphia (DOT) net
jchirco (AT) innout (DOT) com



Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: sum up datatype of table of numbers - 12-18-2004 , 01:44 PM






Jeff Chirco wrote:

Quote:
Ok, I have created my own datatype called num_tab as a table of numbers.
And now I am creating a function where I go through in a loop and insert
differnet numbers into this table of numbers through a variable called
v_numtab. At the end of my function I have to sum up all the numbers in
this table/variable. That is what I don't know how to do. Normally it is
easy to do because I know the column name, but with this datatype created I
dont know the column name. Does anybody know how to sum everything up from
it. I was thinking select sum(v_numtab) from dual; But that didn't work.
Any ideas would be appreciated. Thanks. Please email me with ideas.
Please send to both email addresses. Thank again.


Jeff Chirco
jchirco (AT) adelphia (DOT) net
jchirco (AT) innout (DOT) com
Do you mean something like this?

CREATE OR REPLACE TYPE NumTab_t IS TABLE OF NUMBER(5);
/

set serveroutput on

DECLARE

numary NumTab_t;
x PLS_INTEGER := 0;

BEGIN
-- initialize collection
numary := NumTab_t(0);
-- extend the collection to the size of the PL/SQL table
numary.EXTEND(4);

-- for each element in the PL/SQL table
FOR i IN 1 .. 5
LOOP
numary(i) := i;
END LOOP;

-- sum the values
FOR j IN 1 .. numary.COUNT
LOOP
x := x + numary(j);
END LOOP;

dbms_output.put_line('Sum of values = ' || x);
END;
/

--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace 'x' with 'u' to respond)


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----


Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.