GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Added help function to objects.sql · webdeveloper987/test_db@99441fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objects.sql
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objects.sql‎

Copy file name to clipboardExpand all lines: objects.sql
+78-41Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ drop function if exists emp_dept_id //
55
drop function if exists emp_dept_name //
66
drop function if exists emp_name //
77
drop function if exists current_manager //
8+
drop procedure if exists show_departments //
89

910
--
1011
-- returns the department id of a given employee
@@ -15,22 +16,22 @@ reads sql data
1516
begin
1617
declare max_date date;
1718
set max_date = (
18-
select
19-
max(from_date)
20-
from
21-
dept_emp
22-
where
19+
select
20+
max(from_date)
21+
from
22+
dept_emp
23+
where
2324
emp_no = employee_id
2425
);
2526
set @max_date=max_date;
2627
return (
27-
select
28+
select
2829
dept_no
29-
from
30+
from
3031
dept_emp
31-
where
32+
where
3233
emp_no = employee_id
33-
and
34+
and
3435
from_date = max_date
3536
limit 1
3637
);
@@ -47,7 +48,7 @@ begin
4748
return (
4849
select
4950
dept_name
50-
from
51+
from
5152
departments
5253
where
5354
dept_no = emp_dept_id(employee_id)
@@ -62,11 +63,11 @@ returns varchar(32)
6263
reads SQL data
6364
begin
6465
return (
65-
select
66+
select
6667
concat(first_name, ' ', last_name) as name
67-
from
68+
from
6869
employees
69-
where
70+
where
7071
emp_no = employee_id
7172
);
7273
end//
@@ -82,22 +83,22 @@ reads sql data
8283
begin
8384
declare max_date date;
8485
set max_date = (
85-
select
86-
max(from_date)
87-
from
88-
dept_manager
89-
where
86+
select
87+
max(from_date)
88+
from
89+
dept_manager
90+
where
9091
dept_no = dept_id
9192
);
9293
set @max_date=max_date;
9394
return (
94-
select
95+
select
9596
emp_name(emp_no)
96-
from
97+
from
9798
dept_manager
98-
where
99+
where
99100
dept_no = dept_id
100-
and
101+
and
101102
from_date = max_date
102103
limit 1
103104
);
@@ -112,16 +113,16 @@ delimiter ;
112113

113114
CREATE OR REPLACE VIEW v_full_employees
114115
AS
115-
SELECT
116-
emp_no,
117-
first_name , last_name ,
118-
birth_date , gender,
116+
SELECT
117+
emp_no,
118+
first_name , last_name ,
119+
birth_date , gender,
119120
hire_date,
120-
emp_dept_name(emp_no) as department
121-
from
121+
emp_dept_name(emp_no) as department
122+
from
122123
employees;
123124

124-
--
125+
--
125126
-- selects the department list with manager names
126127
--
127128

@@ -138,7 +139,6 @@ delimiter //
138139
-- shows the departments with the number of employees
139140
-- per department
140141
--
141-
drop procedure if exists show_departments //
142142
create procedure show_departments()
143143
modifies sql data
144144
begin
@@ -153,36 +153,73 @@ begin
153153
);
154154
INSERT INTO department_max_date
155155
SELECT
156-
emp_no, max(from_date), max(to_date)
156+
emp_no, max(from_date), max(to_date)
157157
FROM
158158
dept_emp
159159
GROUP BY
160160
emp_no;
161161

162-
CREATE TEMPORARY TABLE department_people
162+
CREATE TEMPORARY TABLE department_people
163163
(
164164
emp_no int not null,
165165
dept_no char(4) not null,
166166
primary key (emp_no, dept_no)
167167
);
168168

169-
insert into department_people
169+
insert into department_people
170170
select dmd.emp_no, dept_no
171-
from
172-
department_max_date dmd
173-
inner join dept_emp de
174-
on dmd.dept_from_date=de.from_date
171+
from
172+
department_max_date dmd
173+
inner join dept_emp de
174+
on dmd.dept_from_date=de.from_date
175175
and dmd.dept_to_date=de.to_date
176176
and dmd.emp_no=de.emp_no;
177-
SELECT
178-
dept_no,dept_name,manager, count(*)
179-
from v_full_departments
180-
inner join department_people using (dept_no)
177+
SELECT
178+
dept_no,dept_name,manager, count(*)
179+
from v_full_departments
180+
inner join department_people using (dept_no)
181181
group by dept_no;
182182
# with rollup;
183183
DROP TABLE department_max_date;
184184
DROP TABLE department_people;
185185
end //
186186

187+
drop function if exists employees_usage //
188+
drop procedure if exists employees_help //
189+
190+
CREATE FUNCTION employees_usage ()
191+
RETURNS TEXT
192+
DETERMINISTIC
193+
BEGIN
194+
RETURN
195+
'
196+
== USAGE ==
197+
====================
198+
199+
PROCEDURE show_departments()
200+
201+
shows the departments with the manager and
202+
number of employees per department
203+
204+
FUNCTION current_manager (dept_id)
205+
206+
Shows who is the manager of a given departmennt
207+
208+
FUNCTION emp_name (emp_id)
209+
210+
Shows name and surname of a given employee
211+
212+
FUNCTION emp_dept_id (emp_id)
213+
214+
Shows the current department of given employee
215+
';
216+
END //
217+
218+
create procedure employees_help()
219+
deterministic
220+
begin
221+
select employees_usage() as info;
222+
end//
223+
187224
delimiter ;
188225

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.