473,769 Members | 7,315 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use plsql to calculate compond growth

I am learning plsql. I would like to run a stored procedure to
calculate my bank account value by predicted 10% annual growth rate.
Below is my plsql that is having problems. Your help is highly
appreciated.

Thanks

declare
money number := 50000.00;
year number := 1;
begin for i in 1..17
loop
execute immediate 'insert into my_401k values (':year', 'money + 0.10
* money')';
year := year + 1;
end loop;
end;
/
SP2-0552: Bind variable "YEAR" not declared.

Any where wrong in this script?

Thanks
Jul 19 '05
11 7800
Frank van Bortel <fv********@net scape.net> wrote in message news:<bs******* ***@news2.tilbu 1.nb.home.nl>.. .
Ken Denny wrote:
nu**********@re diffmail.com (nullpointer) wrote in
news:c0******** *************** ***@posting.goo gle.com:

PL SQL autobinds so no need to specify those as bind variables
This should work

1 declare
2 money number :=50000.00;
3 year number :=1;
4 begin for i in 1..17
5 loop insert into my_401k values(year, money + 0.1*money);
6 year := year +1;
7 end loop;
8* end;

Hope it Helps
nullpointer

That will get around the error message, but it won't give you the results
you're looking for. Note: you never changed the value of the variable
money, so every year money is going to have 55000.00 in the moey column.

1 declare
2 money number := 50000.00;
3 year number := 1;
4 begin
5 for i in 1..17
6 loop
7 money := money *1.1;
8 execute immediate 'insert into my_401k values (:y,:m)'
9 using year, money;
10 year := year + 1;
11 end loop;
12* end;

SQL> col money for 999,999,990.00
SQL> select * from my_401k;

YEAR MONEY
---------- ---------------
1 55,000.00
2 60,500.00
3 66,550.00
4 73,205.00
5 80,525.50
6 88,578.05
7 97,435.86
8 107,179.44
9 117,897.38
10 129,687.12
11 142,655.84

YEAR MONEY
---------- ---------------
12 156,921.42
13 172,613.56
14 189,874.92
15 208,862.41
16 229,748.65
17 252,723.51

17 rows selected.

Frank,

How about if I add 12000 anually to my account? How to calculate that?

Best Regards,

David
Jul 19 '05 #11
David wrote:
Frank van Bortel <fv********@net scape.net> wrote in message news:<bs******* ***@news2.tilbu 1.nb.home.nl>.. .
Ken Denny wrote:

nu********** @rediffmail.com (nullpointer) wrote in
news:c0***** *************** ******@posting. google.com:

PL SQL autobinds so no need to specify those as bind variables
This should work

1 declare
2 money number :=50000.00;
3 year number :=1;
4 begin for i in 1..17
5 loop insert into my_401k values(year, money + 0.1*money);
6 year := year +1;
7 end loop;
8* end;

Hope it Helps
nullpoint er
That will get around the error message, but it won't give you the results
you're looking for. Note: you never changed the value of the variable
money, so every year money is going to have 55000.00 in the moey column.


1 declare
2 money number := 50000.00;
3 year number := 1;
4 begin
5 for i in 1..17
6 loop
7 money := money *1.1;
8 execute immediate 'insert into my_401k values (:y,:m)'
9 using year, money;
10 year := year + 1;
11 end loop;
12* end;

SQL> col money for 999,999,990.00
SQL> select * from my_401k;

YEAR MONEY
---------- ---------------
1 55,000.00
2 60,500.00
3 66,550.00
4 73,205.00
5 80,525.50
6 88,578.05
7 97,435.86
8 107,179.44
9 117,897.38
10 129,687.12
11 142,655.84

YEAR MONEY
---------- ---------------
12 156,921.42
13 172,613.56
14 189,874.92
15 208,862.41
16 229,748.65
17 252,723.51

17 rows selected.


Frank,

How about if I add 12000 anually to my account? How to calculate that?

Best Regards,

David


It's in there - here it goes with comments:
-- this is a so-called anonymous PL/SQL block; it has no
-- Procedure name.
declare -- Start declaration section - yes I have done Cobol...
money number := 50000.00; -- define a variable named "money" as
-- a number, and initialize it
year number := 1; -- ditto, for "year"
begin -- The PL/SQL starts here
for i in 1..17 -- initialize a loop variable
loop -- top end of the loop
money := money *1.1; -- recalculate "money", up it with 10%
execute immediate 'insert into my_401k values (:y,:m)'
using year, money; -- actual insert into table
year := year + 1; -- recalculate the year, up it with 1
end loop; -- OK that's all from the loop.
-- If i reached the value 17 we would
-- be done
end; -- nothing left to do after the
-- loop completes, tell PL/SQL to stop

I'll leave it up to you how to add 12k annually, instead of 10%
--
A prosperous 2004,
Regards,
Frank van Bortel

Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3434
by: Corrine | last post by:
I am trying to pass a temporary BLOB that I've created in Java, to a PLSQL function that modifies it, and then to retrieve this modified value back to Java, all using JDBC. I can't figure out how to get the modified BLOB object back to Java after the PLSQL block has finished executing. I do: BLOB bl = BLOB.createTemporary(db,true,BLOB.DURATION_SESSION);
3
1669
by: eric.nave | last post by:
In a situation where you have two tables in a hierarchy like this: create table authors (authorid int identity (1,1)) create table books ( authorid int, bookid int identity (1,1) ) Is there any disadvantage to having the primary key and the clustered
15
4193
by: marvado | last post by:
Hi, can I run phpinfo(); or any php code from an oracle plsql package using htp.p from the oracle web toolkit owa? what I need is to run any php code using htp.p() I might be missing something, in my oracle/apache/php configuration I can only run flat .php files from /htdocs but can't run any php from a plsql procedure to display on a browser with htp.p
6
8056
by: Tom | last post by:
Hello, please help me, I need two write a C++ program that can calculate the number of days between two dates.
0
2107
by: kux | last post by:
Hello everyone, I hope someone is out here who can help me with a simple calculation... I have a sales data base in access with monthly sales history by product. to make future predictions I need the slope (representing growth) of monthly sales. the data is setup in a crosstab with the months in different collums, say column 1 to 12 for last year. I want to calculate the slope for every row (on the same query or another if needed)
5
7631
by: kux | last post by:
Hello everyone, I hope someone is out here who can help me with a simple calculation... I have a sales data base in access with monthly sales history by product. to make future predictions I need the slope (representing growth) of monthly sales. the data is setup in a crosstab with the months in different collums, say column 1 to 12 for last year. I want to calculate the slope for every row (on the same query or another if needed)
0
4090
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should return me Array element type code 1, but it is returning me type code 12 and the array in a junk or unreadable format . Our environment is JDK 1.4, ojdbc14.jar and Oracle 8i Not able to find out what they problem is and am not able to change the...
0
1345
by: sybrandb | last post by:
"Jorge Pinto" <jorgep@sympatico.cawrote in message news:<L2HQa.3116$104.264170@news20.bellglobal.com>... utl_smtp is only a wrapper for a java procedure. Need I say more. And oh yes, you may need to check your DBA actually configured the java_pool_size, or he is going to be in for some nasty surprises. Sybrand Bakker Senior Oracle DBA
11
379
by: David | last post by:
I am learning plsql. I would like to run a stored procedure to calculate my bank account value by predicted 10% annual growth rate. Below is my plsql that is having problems. Your help is highly appreciated. Thanks declare money number := 50000.00; year number := 1;
0
10219
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.