• Post author:
  • Post category:PLSQL
  • Reading time:1 mins read

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

Advertisement

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;
Related:  How to Get Current Date in PL/SQL?

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.