473,385 Members | 1,564 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,385 software developers and data experts.

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 #1
11 7750

"David" <ni*******@yahoo.com> wrote in message
news:37*************************@posting.google.co m...
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
Much simpler and more efficient to:(no need for execute immediate) declare
money number := 50000.00;
year number := 1;
begin for i in 1..17
loop insert into my_401k values (:year, :money + 0.10* :money); year := year + 1;
end loop;
end;
/

Jul 19 '05 #2

"Jim Kennedy" <ke****************************@attbi.net> wrote in message
news:oqvHb.682774$Fm2.590452@attbi_s04...
|
| "David" <ni*******@yahoo.com> wrote in message
| news:37*************************@posting.google.co m...
| > 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
|
| Much simpler and more efficient to:(no need for execute immediate)
| > declare
| > money number := 50000.00;
| > year number := 1;
| > begin for i in 1..17
| > loop
| insert into my_401k values (:year, :money + 0.10* :money);
| > year := year + 1;
| > end loop;
| > end;
| > /
| >
|
|

jim's solution is simpler and probably the best way to issue this INSERT,
since the statement is not dynamic (only the values)

however, if you did need to use execute immediate, you could either just
concatenate the local PL/SQL variable value (your concatenation operators
where missing as well):

| > execute immediate 'insert into my_401k values ('||year||', '||money +
0.10||')'

or better yet (again, if execute immediate was necessary because the INSERT
statement was not known at compile time), use proper bind variable syntax
(see the USING keyword in the PL/SQL manual's EXECUTE IMMEDIATE section)

also, a very important reminder, and an observation

[_] always (always, always, always) explicitly list the column in your
INSERT statement -- never rely on insert into TABLE values (....); as soon
as the structure of the table changes, your code breaks
[_] do you really need a persistent record of the values stored in the
database? if not, don't do database inserts when a simply using PL/SQL
variables would suffice
--
Mark C. Stock
mcstock -> enquery(dot)com
www.enquery.com training & consulting


Jul 19 '05 #3
Hi Jim,

Thank you for your help. I still got the same error message based on your code

Any where wrong?

Thanks

David

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;
nli@HOPE1> /
SP2-0552: Bind variable "MONEY" not declared.


ni*******@yahoo.com (David) wrote in message news:<37*************************@posting.google.c om>...
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 #4
David wrote:

Hi Jim,

Thank you for your help. I still got the same error message based on your code

Any where wrong?

Thanks

David

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;
nli@HOPE1> /
SP2-0552: Bind variable "MONEY" not declared.

ni*******@yahoo.com (David) wrote in message news:<37*************************@posting.google.c om>...
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


Since this is a PL/SQL variable, does it need to be bound? What happens
when you drop the semi-colons?

What I understand from bind variables is they are used to bind between
the host environment (eg C, VB, SQL*Plus) and the SQL & PL/SQL
environment. Flames for correction appreciated.

/Hans
Jul 19 '05 #5
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

***********************************************

ni*******@yahoo.com (David) wrote in message news:<37**************************@posting.google. com>...
Hi Jim,

Thank you for your help. I still got the same error message based on your code

Any where wrong?

Thanks

David

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;
nli@HOPE1> /
SP2-0552: Bind variable "MONEY" not declared.


ni*******@yahoo.com (David) wrote in message news:<37*************************@posting.google.c om>...
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 #6
nu**********@rediffmail.com (nullpointer) wrote in
news:c0**************************@posting.google.c om:
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.

--
Ken Denny
http://www.kendenny.com/
Jul 19 '05 #7
Hans Forbrich wrote:
David wrote:
Hi Jim,

Thank you for your help. I still got the same error message based on your code

Any where wrong?

Thanks

David

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;
nli@HOPE1> /
SP2-0552: Bind variable "MONEY" not declared.

ni*******@yahoo.com (David) wrote in message news:<37*************************@posting.google.c om>...
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

Since this is a PL/SQL variable, does it need to be bound? What happens
when you drop the semi-colons?

What I understand from bind variables is they are used to bind between
the host environment (eg C, VB, SQL*Plus) and the SQL & PL/SQL
environment. Flames for correction appreciated.

/Hans


No - it does not need binding; just loose the ':' (and quotes):
insert into my_401k values(year, 1.1*money) ;

The exec imm *can* use bind variables:
execute immediately ('insert into my_401k values(:y, :m)'
using year, money * 1.1;

Have never used the using money * 1.1 sytax though, so it's
without warrenty.
Oh - heck:
SQL> create table my_401k (year number, money number(12,2));
1 declare
2 money number := 50000.00;
3 year number := 1;
4 begin
5 for i in 1..17
6 loop
7 execute immediate 'insert into my_401k values (:y,:m)'
8 using year, money * 1.1;
9 year := year + 1;
10 end loop;
11* end;
SQL> /

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> select * from my_401k;

YEAR MONEY
---------- ----------
1 55000
2 55000
3 55000
4 55000
5 55000
6 55000
7 55000
8 55000
9 55000
10 55000
11 55000

YEAR MONEY
---------- ----------
12 55000
13 55000
14 55000
15 55000
16 55000
17 55000

--
A prosperous 2004,
Regards,
Frank van Bortel

Jul 19 '05 #8
Ken Denny wrote:
nu**********@rediffmail.com (nullpointer) wrote in
news:c0**************************@posting.google.c om:

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.

--
A prosperous 2004,
Regards,
Frank van Bortel

Jul 19 '05 #9
Frank van Bortel <fv********@netscape.net> wrote in message news:<bs**********@news2.tilbu1.nb.home.nl>...
Ken Denny wrote:
nu**********@rediffmail.com (nullpointer) wrote in
news:c0**************************@posting.google.c om:

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,

Thank you very much. That is exactly I was looking for.

Have a Happy and Prosporous New Year!

David
Jul 19 '05 #10
Frank van Bortel <fv********@netscape.net> wrote in message news:<bs**********@news2.tilbu1.nb.home.nl>...
Ken Denny wrote:
nu**********@rediffmail.com (nullpointer) wrote in
news:c0**************************@posting.google.c om:

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********@netscape.net> wrote in message news:<bs**********@news2.tilbu1.nb.home.nl>...
Ken Denny wrote:

nu**********@rediffmail.com (nullpointer) wrote in
news:c0**************************@posting.googl e.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


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
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...
3
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...
15
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...
6
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
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...
5
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...
0
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...
0
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...
11
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.