问题
Possible Duplicate:
Homework on PL/SQL FUNCTIONS
plsql functions
Function:
- function to
Display_Employee_Name_In_Uppercasethat accepts theEmployee_IDfrom theEmpoyeestable and returns the first and the last name of the employee in uppercase. - Write a small PL/SQL program to display the names of the employees whose
Employee_IDsare 107, 200 and 205.
this is what I have done I didnt know how to complete it can help ?
CREATE OR REPLACE FUNCTION disp (emp_id in varchar20) return emp_name
select into emp_name
fname||lname
from employees
where employee_id=emp_id
END disp ;
回答1:
Something like this...
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;
You can call this function wherever you want. here is a sample...
DECLARE
empId VARCHAR2(100);
empName VARCHAR2(100);
BEGIN
empId := &ENTER_EMPLOYEE_ID;
empName := Fn_Display(empId);
DBMS_OUTPUT.PUT_LINE('Employee Name: '||empName);
END;
回答2:
You could try this code, maybe this one works for you:
CREATE OR REPLACE FUNCTION disp (emp_id in varchar2) return varchar2 IS
emp_name varchar2(256);
BEGIN
select UPPER(fname || ' ' || lname)
into emp_name
from employees
where employee_id = emp_id;
return emp_name;
END disp;
来源:https://stackoverflow.com/questions/10512495/pl-sql-functions