简体   繁体   English

为什么我的PL / SQL过程编译时出现错误

[英]Why is my PL/SQL Procedure compiling with Errors

Been working on this block of code for 3-days. 在此代码块上工作了3天。 Read the book chapter twice on procedures and it isn't much help. 两次阅读有关过程的书,这并没有太大帮助。 There aren't any reference code blocks as examples. 没有任何参考代码块作为示例。 Those obviously are perfect examples to walk through the steps. 这些显然是完成这些步骤的完美示例。 Either way I'd like for someone to comment on my code and tell me why it will not compile. 无论哪种方式,我都希望有人评论我的代码并告诉我为什么它无法编译。

What I am trying to do is verify payment information using (IN and OUT parameters) Accept a ID for in and return three values (donation amount, donation total to date if it were paid over time like 12 months and balance remaining). 我想做的是使用(IN和OUT参数)验证付款信息,并接受一个I​​D,并返回三个值(捐赠金额,迄今为止的捐赠总额(如果已按时支付12个月)以及余额。 Hoping someone will be able to help me with this. 希望有人能够帮助我。 I've read the Oracle docs site and i'm still lost on these procedures. 我已经阅读了Oracle文档站点,但仍然对这些过程一无所知。

My Code: 我的代码:

CREATE OR REPLACE PROCEDURE DDCKBAL_SP
(pl_id  IN dd_pledge.idpledge%TYPE,
pl_amount OUT NUMBER,
pay_to_date OUT NUMBER,
p_balance OUT NUMBER)

IS
pay_amount      dd_payment.payamt%TYPE; --variable to calculate pay
pay_months      dd_pledge.paymonths%TYPE; --variable for calculations

BEGIN
SELECT  pledgeamt, pay_amount --Edited here
INTO pl_amount, pay_to_date  --Edits here
FROM dd_pledge 
WHERE idpledge = pl_id;

IF pay_months = 0 THEN
pay_to_date := pl_amount; 
ELSE pay_to_date := pl_amount *(pl_amount/pay_months);
p_balance := pl_amount - pay_to_date;
END IF;

END DDCKBAL_SP;

/* The above now compiles, however when I run a test I receive the total 
 amount pledged but nothing for paid_to_date (if pledge was for 1200 
 over 12 payments wouldn't it be $20 a month up to current date?

 I'm not receiving output for balance either...Starting to get the hang
of this but still need a bit of help with explanations */

The & is for SQL Plus replacement functionality where the application prompts you for values before sending them to the Oracle server. &是用于SQL Plus替换功能的,其中应用程序在将值发送到Oracle服务器之前提示您输入值。 You're looking for variable binding, and that's with a : . 您正在寻找变量绑定,并且带有:

For instance, from the Oracle docs : http://docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci05bnd.htm 例如, 从Oracle文档中http : //docs.oracle.com/cd/B10501_01/appdev.920/a96584/oci05bnd.htm

You also might not need binding, but you'll need to dump the & . 您可能还不需要绑定,但是您需要转储&

CREATE OR REPLACE PROCEDURE procOneINOUTParameter(genericParam IN OUT VARCHAR2)
IS
BEGIN

  genericParam := 'Hello World INOUT parameter ' || genericParam;

END;

If you want to learn about bind variables, look here . 如果您想了解绑定变量, 请看这里 It allows you to save on parsing, but right now I think that's more complex to think about than what you need. 它可以让您节省解析的时间,但是现在我认为考虑起来比您需要的要复杂得多。

Bind variables allow a single SQL statement (whether a query or DML) to be re-used many times, which helps security (by disallowing SQL injection attacks) and performance (by reducing the amount of parsing required). 绑定变量允许多次重复使用一条SQL语句(无论是查询还是DML),从而有助于提高安全性(通过禁止SQL注入攻击)和性能(通过减少所需的分析量)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM