Press "Enter" to skip to content

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

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *