Can we have a function inside procedure?
Sure we can
CREATE OR REPLACE PROCEDURE sp_test (ID IN number)
AS
FUNCTION fn_test (Id IN number)
RETURN varchar 2
IS
DECLARE eName varchar2(50);
BEGIN
SELECT Emp_Name INTO eName
FROM emp WHERE EmpId = Id;
RETURN oID;
EXCEPTION
WHEN no_data_found THEN
eName:= NULL;
RETURN eName;
END;
BEGIN
IF(fn_test (ID) IS NULL) THEN
RAISE_APPLICATION_ERROR(-20001,'EmpId is not valid');
END IF;
END;
/
The only disadvantage with this, you will not be able to use this function from any other packages or procedures
No comments:
Post a Comment