简体   繁体   中英

oracle update stored procedure with user defined exception

I am trying to create this stored procedure which should take customer no and email address as input. Then update the email address for that customer. if new email address is same as old then exception should be raised.

CREATE OR REPLACE PROCEDURE UpdateEmail
(CUSTOMERID IN CUSTOMER.CUSTOMERNO%TYPE, 
 N_EMAIL IN CUSTOMER.EMAIL%TYPE)

IS
DECLARE 
  e_same EXCEPTION;
  V_ROWCOUNT NUMBER;

BEGIN
SELECT COUNT(EMAIL)
INTO V_ROWCOUNT
FROM CUSTOMER@FIT5148B
WHERE CUSTOMER.EMAIL = N_EMAIL
AND CUSTOMER.CUSTOMERNO = CUSTOMERID;

IF V_ROWCOUNT > 0

THEN RAISE e_same;
ELSE 
UPDATE CUSTOMER
SET EMAIL = N_EMAIL
WHERE CUSTOMER.CUSTOMERNO = CUSTOMERID;
END IF;

EXCEPTION
 WHEN e_same THEN dbms_output.put_line ('email address exist');
END;
/

But it is throwing error. Not sure if I am doing it right. I am using the latest Oracle SQL Developer.

Error(6,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: begin function pragma procedure subtype type current cursor delete exists prior external language The symbol "begin" was substituted for "DECLARE" to continue.
Error(28,4): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ( begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge

Remove DECLARE .

You should not use Declare in a Procedure. If you are writing a PLSQL block then only you should use Declare . Not in an actual Procedure body.

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