Thursday, September 3, 2009

CREATE FUNCTION

Create a function to get account name by account id.


CREATE OR REPLACE FUNCTION fnGetAccountNameByID(vACCOUNT_ID IN NUMBER)
RETURN VARCHAR2 IS vACCOUNT_NAME VARCHAR2(255);
BEGIN
vACCOUNT_NAME := '';
SELECT ACCOUNT_NAME INTO vACCOUNT_NAME
FROM ACCOUNT
WHERE ACCOUNT_ID = vACCOUNT_ID;

RETURN vACCOUNT_NAME;

EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END fnGetAccountNameByID;
/

No comments:

Post a Comment