-
Notifications
You must be signed in to change notification settings - Fork 1
/
FUNCTION.sql
38 lines (32 loc) · 1.26 KB
/
FUNCTION.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Function
-- Numarasi verilen departmanin ismini listeleyecegiz.
CREATE OR REPLACE FUNCTION d_name(p_dept departments.department_id%type)
RETURN departments.department_name%type
IS wname departments.department_name%type;
Begin
select departments.department_name into wname
from departments
where departments.department_id = p_dept;
RETURN wname;
End;
/
SELECT d_name(60) FROM DUAL;
-- EMPLOYEE ID'si girilen calisanin is gecmisini listeleyecegiz.
CREATE OR REPLACE FUNCTION d_emp (p_emp employees.employee_id%type)
RETURN varchar2
IS
w_start_date job_history.start_date%type;
w_end_date job_history.end_date%type;
w_job_id job_history.job_id%type;
w_dept_id job_history.department_id%type;
w_result varchar2(150);
Begin
select jh.start_date, jh.end_date, jh.job_id, jh.department_id
into w_start_date, w_end_date, w_job_id, w_dept_id
from job_history jh
where jh.employee_id = p_emp;
w_result := (w_start_date || ' - ' || w_end_date || ' - ' || w_job_id || ' - ' || w_dept_id);
RETURN w_result;
End;
/
SELECT d_emp(102) FROM DUAL;