-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopdept.sql
More file actions
36 lines (32 loc) · 1.17 KB
/
Copy pathpopdept.sql
File metadata and controls
36 lines (32 loc) · 1.17 KB
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
create or replace procedure cmpsys.popdept()
language sql
Result Sets 0
Modifies SQL Data
Specific popdept
begin
declare i int default 1;
declare deptno char(3);
declare deptname varchar(36);
declare mgrno char(6);
declare admrdept char(3);
declare loc char(16);
while i <= 5 do
-- Generate random data (you can adjust this as needed)
set deptno = right('000' || cast(rand()*1000 as int), 3);
set mgrno = right('00000' || cast(rand()*1000000 as int), 6);
set admrdept = right('000' || cast(rand()*1000 as int), 3);
set loc = 'Location ' || deptno;
-- Assign department names based on specified categories
case
when i = 1 then set deptname = 'Admin';
when i = 2 then set deptname = 'IT';
when i = 3 then set deptname = 'Finance';
when i = 4 then set deptname = 'Management';
when i = 5 then set deptname = 'HR';
end case;
-- Insert into department table
insert into cmpsys.department (deptno, deptname, mgrno, admrdept, location)
values (deptno, deptname, mgrno, admrdept, loc);
set i = i + 1;
end while;
end;