fork download
  1. CREATE OR REPLACE FUNCTION get_employee_info(emp_id IN NUMBER) RETURN VARCHAR2 IS
  2.  
  3. v_emp_name SCOTT.EMP.ENAME%TYPE;
  4. v_emp_job SCOTT.EMP.JOB%TYPE;
  5. v_emp_mgr SCOTT.EMP.MGR%TYPE;
  6. v_emp_hiredate SCOTT.EMP.HIREDATE%TYPE;
  7. v_emp_salary SCOTT.EMP.SAL%TYPE;
  8. v_emp_comm SCOTT.EMP.COMM%TYPE;
  9. v_emp_deptno SCOTT.EMP.DEPTNO%TYPE;
  10. v_emp_output VARCHAR2(4000);
  11.  
  12. BEGIN
  13. SELECT ename, job, mgr, hiredate, sal, comm, deptno
  14. INTO v_emp_name, v_emp_job, v_emp_mgr, v_emp_hiredate, v_emp_salary, v_emp_comm, v_emp_deptno
  15. FROM SCOTT.EMP
  16. WHERE empno = emp_id;
  17.  
  18. v_emp_output := 'Employee ID: ' || emp_id || CHR(10) ||
  19. 'Name: ' || v_emp_name || CHR(10) ||
  20. 'Job: ' || v_emp_job || CHR(10) ||
  21. 'Manager ID: ' || NVL(TO_CHAR(v_emp_mgr), 'N/A') || CHR(10) ||
  22. 'Hire Date: ' || TO_CHAR(v_emp_hiredate, 'DD-MON-YYYY') || CHR(10) ||
  23. 'Salary: ' || TO_CHAR(v_emp_salary) || CHR(10) ||
  24. 'Commission: ' || NVL(TO_CHAR(v_emp_comm), 'N/A') || CHR(10) ||
  25. 'Department Number: ' || TO_CHAR(v_emp_deptno);
  26.  
  27. RETURN v_emp_output;
  28.  
  29. END;
  30. /
  31.  
  32.  
  33. DECLARE
  34. v_employee_id SCOTT.EMP.EMPNO%TYPE := 7369;
  35.  
  36.  
  37. v_employee_info VARCHAR2(4000);
  38. BEGIN
  39.  
  40. v_employee_info := get_employee_info(v_employee_id);
  41.  
  42.  
  43. DBMS_OUTPUT.PUT_LINE(v_employee_info);
  44.  
  45. END;
  46. /
  47.  
Success #stdin #stdout #stderr 0.01s 5264KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "OR": syntax error
Error: near line 4: near "v_emp_job": syntax error
Error: near line 5: near "v_emp_mgr": syntax error
Error: near line 6: near "v_emp_hiredate": syntax error
Error: near line 7: near "v_emp_salary": syntax error
Error: near line 8: near "v_emp_comm": syntax error
Error: near line 9: near "v_emp_deptno": syntax error
Error: near line 10: near "v_emp_output": syntax error
Error: near line 12: near "SELECT": syntax error
Error: near line 18: near "v_emp_output": syntax error
Error: near line 27: near "RETURN": syntax error
Error: near line 29: cannot commit - no transaction is active
Error: near line 33: near "DECLARE": syntax error
Error: near line 37: near "v_employee_info": syntax error
Error: near line 38: near "v_employee_info": syntax error
Error: near line 43: near "DBMS_OUTPUT": syntax error
Error: near line 45: cannot commit - no transaction is active