-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice_10_multiple_solutions.sql
49 lines (41 loc) · 1.33 KB
/
practice_10_multiple_solutions.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
39
40
41
42
43
44
45
46
47
48
49
10_1
DECLARE
v_job_id VARCHAR2(15);
job_name VARCHAR2(15);
BEGIN
select job_id into v_job_id from employees where employee_id=:id;
if v_job_id='ST_CLERK' then job_name:= 'STOCK CLERK';
if v_job_id=‘IT_PROG’ then job_name:= ‘PROGRAMMER’;
else job_name:= 'other job';
end if;
END;
10_2
SQL Solution
SELECT last_name, job_id, case job_id When 'ST_CLERK' then 'Stock Clerk'
When 'IT_PROG' then 'Sales PROGRAMMER'
ELSE 'other job' END job_name
FROM employees
WHERE employee_id =:id;
PL/SQL Solution
DECLARE
v_job_id VARCHAR2(15);
job_name VARCHAR2(15);
BEGIN
select job_id into v_job_id from employees where employee_id=:id;
case v_job_id when 'ST_CLERK' then job_name:= 'Stock Clerk';
when 'IT_PROG' then job_name := 'PROGRAMMER';
else job_name := 'other job';
end case;
END;
display version
DECLARE
v_job_id VARCHAR2(15);
job_name VARCHAR2(15);
BEGIN
select job_id into v_job_id from employees where employee_id=:id;
case v_job_id when 'ST_CLERK' then job_name:= 'Stock Clerk';
when 'IT_PROG' then job_name := 'PROGRAMMER';
else job_name := 'other job';
end case;
DBMS_OUTPUT.PUT_LINE('his job id is '||v_job_id||', and the job name is '||job_name);
END;