简体   繁体   中英

Why is my PL/SQL Procedure compiling with Errors

Been working on this block of code for 3-days. 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). 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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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