PL/SQL Functions

A function is a PL/SQL block with names that accept parameters, can be called in a select and can return a value.

Functions and procedures are similar structures.

A function may return a single value, while a procedure may return zero or more values through parameters.


Create Function Example:
CREATE OR REPLACE FUNCTION Stu_Name(p_id IN NUMBER)
RETURN VARCHAR2
IS
   stu_row students%ROWTYPE;
   v_full_name VARCHAR2(255):='';
BEGIN
   SELECT * INTO stu_row
   FROM students WHERE student_id=3;
   v_full_name:=stu_row.first_name||' '||stu_row.last_name;
   RETURN v_full_name;
END;