如何使用plsql来计算compond增长 [英] how to use plsql to calculate compond growth

查看:142
本文介绍了如何使用plsql来计算compond增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习plsql。我想运行一个存储过程来计算我的银行账户价值,预测10%的年增长率。

下面是我的plsql有问题。你的帮助非常高。

赞赏。


谢谢


申报

钱数:= 50000.00;

年份数字:= 1;

从1开始为i .17

循环

执行立即''插入my_401k值('':年'',''钱+ 0.10

*钱'')'';

年:=年+ 1;

结束循环;

结束;

/

SP2-0552:绑定变量YEAR ;没有宣布。


这个剧本中哪里出错?


谢谢

解决方案



" David" < NI ******* @ yahoo.com>在消息中写道

news:37 ************************* @ posting.google.co m ... < blockquote class =post_quotes>我正在学习plsql。我想运行一个存储过程来按照预测的10%年增长率计算我的银行账户值。
下面是我的plsql有问题。感谢您的帮助。

谢谢

声明
金额:= 50000.00;
年数:= 1;
开始为我在1..17
执行立即''插入my_401k值('':年'',''钱+ 0.10
*钱'')' ';
年份:=年+ 1;
结束循环;
结束;
/

SP2-0552:绑定变量YEAR没有宣布。

这个剧本中哪里出错?

谢谢


更简单,更高效:(不需要执行立即)声明
钱数:= 50000.00;
年数:= 1;
以1开始为i .17循环
插入my_401k值( :年,:钱+ 0.10 *:钱);年:=年+ 1;
结束循环;
结束;
/





吉姆肯尼迪 <柯**************************** @ attbi.net>在消息中写道

news:oqvHb.682774


Fm2.590452@attbi_s04 ...

|

| "大卫" < NI ******* @ yahoo.com>在消息中写道

|新闻:37 ************************* @ posting.google.co m ...

| >我正在学习plsql。我想运行一个存储过程来获取
| >按预测的10%年增长率计算我的银行账户价值。

| >下面是我的plsql有问题。你的帮助很高

| >赞赏。

| >

| >谢谢

| >

| >声明

| >钱数:= 50000.00;

| >年份数:= 1;

| >在1..17开始为我支付

| >循环

| >执行立即''插入my_401k值('':年'',''钱+ 0.10

|> *钱'')'';

| >年:=年+ 1;

| >结束循环;

| >结束;

| > /

| >

| >

| > SP2-0552:绑定变量YEAR没有宣布。

| >

| >这个脚本中哪里有错误?

| >

| >谢谢

|

|更简单,更高效:(无需立即执行)

| >声明

| >钱数:= 50000.00;

| >年份数:= 1;

| >在1..17开始为我支付

| >循环

|插入my_401k值(:年,:钱+ 0.10 *:钱);

| >年:=年+ 1;

| >结束循环;

| >结束;

| > /

| >

|

|


jim'的解决方案更简单,可能是发布此INSERT的最佳方式,

因为语句不是动态的(只有值)


但是,如果你确实需要使用execute immediate,你可以只是

连接本地PL / SQL变量值(你的连接操作符

还缺少):


| >执行立即''插入my_401k值(''||年||'',''||钱+

0.10 ||'')''


或更好(再次,如果执行立即是必要的,因为INSERT

语句在编译时是未知的),请使用正确的绑定变量语法

(参见在PL / SQL手册的'EXECUTE IMMEDIATE部分'中使用关键字


也是一个非常重要的提醒和观察


[ _]始终(总是,总是,总是)明确列出

INSERT语句中的列 - 永远不要依赖于插入TABLE值(....);很快

随着表结构的变化,你的代码中断了

[_]你真的需要一个持久记录存储在
$中的值吗? b $ b数据库?如果没有,当简单地使用PL / SQL

变量就足够时,不要做数据库插入

-

Mark C. Stock

mcstock - > enquery(dot)com
www.enquery.com 培训&咨询



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

解决方案


"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 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



这篇关于如何使用plsql来计算compond增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆