-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctionsProcedures.sql
More file actions
73 lines (50 loc) ยท 1.13 KB
/
functionsProcedures.sql
File metadata and controls
73 lines (50 loc) ยท 1.13 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
SELECT * from employees;
SELECT count(*) from employees;
CREATE or replace Function emp_count()
RETURNS void
LANGUAGE SQL
as
$$
DELETE FROM employees WHERE employee_id = 30;
$$;
CREATE or replace Function delete_emp()
RETURNS void
LANGUAGE SQL
as
$$
DELETE FROM employees WHERE employee_id = 30;
$$;
SELECT delete_emp();
CREATE or replace Function delete_emp_by_id(p_emp_id int)
RETURNS void
LANGUAGE SQL
as
$$
DELETE FROM employees WHERE employee_id = p_emp_id;
$$;
SELECT delete_emp_by_id(29)
CREATE Procedure remove_emp_var()
LANGUAGE plpgsql
AS
$$
DECLARE
test_var int;
BEGIN
SELECT employee_id INTO test_var from employees WHERE employee_id = 26;
DELETE FROM employees WHERE employee_id = test_var;
END
$$;
call remove_emp_var();
CREATE Procedure remove_emp_by_id(p_emp_id int)
LANGUAGE plpgsql
AS
$$
DECLARE
test_var int;
BEGIN
SELECT employee_id INTO test_var from employees WHERE employee_id = p_emp_id;
DELETE FROM employees WHERE employee_id = test_var;
RAISE NOTICE 'Employee removed successfully!';
END
$$;
CALL remove_emp_by_id(25)