2021年4月5日星期一

Procedure Output with Exception Handler

I am try to write a code that based on the input of ID and payment amount it will say "Correct Amount" and if not a custom error will raise saying "If it isn't, a custom Oracle error using error number 20050 and the message "Incorrect payment amount – planned payment is " should be raised." "" should be replaced by the correct payment amount. The sample code it

Pledge ID 104 104 100 200

Payment Amount 25 20 250 300

When I run my code all it will say is:

Procedure DDCK_SP compiled

SET SERVEROUTPUT ON    CREATE OR REPLACE PROCEDURE DDCK_SP      (p_id IN NUMBER,      p_amt IN NUMBER,      response OUT VARCHAR2)  -- ONLY ONE OUTPUT NEEDED      IS      a_month dd_pledge.paymonths%TYPE;      a_id    dd_pledge.idpledge%TYPE;      a_amt   dd_pledge.pledgeamt%TYPE;      ttl_amt  dd_pledge.pledgeamt%TYPE;      NO_MONTH EXCEPTOIN;          BEGIN        SELECT idpledge, pledgeamt, paymonths -- COLUMNS FROM TABLE      INTO a_id, a_amt, a_month      FROM dd_pledge      WHERE idpledge = p_id;                 ttl_amt := a_amt/a_month;  IF p_amt = ttl_amt THEN      response:=('Correct amount!');  elsif p_amt != ttl_amt THEN      RAISE_APPLICATION_ERROR(-20050, 'Incorrect payment amount - planned payment is = ' || ttl_amt);     END IF;    EXCEPTION  WHEN NO_DATA_FOUND THEN       DBMS_OUTPUT.PUT_LINE(' No payment found ');  END DDCK_SP;  /  
https://stackoverflow.com/questions/66962248/procedure-output-with-exception-handler April 06, 2021 at 11:14AM

没有评论:

发表评论