How to Execute Function in Oracle With Parameters

In Oracle, you can execute a function with parameters via the following ways:

1. Execute The Function Using Select Statement

SELECT get_emp_job (7566) FROM DUAL;

Output

GET_EMP_JOB(7566) 
----------------------------------------
MANAGER 
1 row selected.

2. Execute The Function Using PL/SQL Block

SET SERVEROUTPUT ON;
DECLARE
v_job emp.job%TYPE;
BEGIN
v_job := get_emp_job (7566);
DBMS_OUTPUT.put_line (v_job);
END;

Output

MANAGER
PL/SQL procedure successfully completed.

Function GET_EMP_JOB

CREATE OR REPLACE FUNCTION GET_EMP_JOB (i_EMPNO IN emp.empno%TYPE)
return varchar2
IS
CURSOR c_ename (p_empno emp.empno%TYPE)
IS
SELECT job
FROM emp
WHERE empno = p_empno;

v_job emp.job%type;
BEGIN
OPEN c_ename (i_empno);

FETCH c_ename INTO v_job;

CLOSE c_ename;

return v_job;

END get_emp_job;
Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 20 years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.