Oracle
 sql >> Database >  >> RDS >> Oracle

Funzioni PL/SQL

Qualcosa del genere...

CREATE OR REPLACE 
FUNCTION Fn_Display(p_empId IN VARCHAR2)
RETURN VARCHAR2

IS

empName VARCHAR2(100);    

BEGIN

 BEGIN
  SELECT UPPER(first_name || ' ' || last_name)
  INTO  empName
  FROM Employees
  WHERE employee_id = p_empId; 
 EXCEPTION 
    WHEN NO_DATA_FOUND THEN
       RAISE NO_DATA_FOUND                
 END;


 RETURN empName;

END Fn_Display;

Puoi chiamare questa funzione dove vuoi. ecco un esempio...

  DECLARE

    empId VARCHAR2(100);
    empName VARCHAR2(100);

  BEGIN

    empId := &ENTER_EMPLOYEE_ID;
    empName := Fn_Display(empId);

    DBMS_OUTPUT.PUT_LINE('Employee Name: '||empName);

  END;