-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben Brumm
committed
Jun 26, 2024
1 parent
af9fc43
commit fa7a858
Showing
9 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* 01 */ | ||
|
||
CREATE OR REPLACE PROCEDURE ShowEmployeesHiredInRange( | ||
v_startdate IN DATE, | ||
v_enddate IN DATE | ||
) | ||
AS | ||
v_empid NUMBER; | ||
v_firstname VARCHAR2(100); | ||
v_lastname VARCHAR2(100); | ||
v_hiredate DATE; | ||
BEGIN | ||
SELECT employee_id, first_name, last_name, hire_date | ||
INTO v_empid, v_firstname, v_lastname, v_hiredate | ||
FROM employees | ||
WHERE hire_date BETWEEN v_startdate AND v_enddate | ||
FETCH FIRST 1 ROWS ONLY; | ||
|
||
DBMS_OUTPUT.PUT_LINE('Employee ' || v_empid || ' ' || | ||
v_firstname || ' ' || v_lastname || ' was hired on ' || | ||
v_hiredate); | ||
END; | ||
|
||
CALL ShowEmployeesHiredInRange(DATE'2005-01-01', DATE'2006-12-13'); | ||
|
||
CALL ShowEmployeesHiredInRange(DATE'2006-12-13', DATE'2005-01-01'); | ||
|
||
CALL ShowEmployeesHiredInRange( | ||
v_startdate => DATE'2005-01-01', | ||
v_enddate => DATE'2006-12-13' | ||
); | ||
|
||
CALL ShowEmployeesHiredInRange( | ||
v_enddate => DATE'2006-12-13', | ||
v_startdate => DATE'2005-01-01' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
SELECT * | ||
FROM employees; | ||
|
||
|
||
CREATE OR REPLACE PROCEDURE InsertEmployeeSimple( | ||
v_firstname IN VARCHAR2, | ||
v_lastname IN VARCHAR2, | ||
v_email IN VARCHAR2, | ||
v_salary IN NUMBER | ||
) | ||
AS | ||
BEGIN | ||
INSERT INTO employees (employee_id, first_name, last_name, email, | ||
phone_number, hire_date, job_id, salary, commission_pct, | ||
manager_id, department_id) | ||
VALUES (employees_seq.nextval, v_firstname, v_lastname, v_email, | ||
NULL, SYSDATE, 'SH_CLERK', v_salary, NULL, | ||
NULL, 50); | ||
|
||
END; | ||
|
||
CALL InsertEmployeeSimple( | ||
v_firstname => 'Ben', | ||
v_lastname => 'Brumm', | ||
v_email => 'BBRUMM', | ||
v_salary => 1000 | ||
); | ||
|
||
|
||
SELECT * | ||
FROM employees | ||
ORDER BY employee_id DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
SELECT * | ||
FROM employees; | ||
|
||
CREATE OR REPLACE PROCEDURE UpdatePeopleContactDetails( | ||
v_emp_id NUMBER, | ||
v_phonenumber VARCHAR2, | ||
v_emailaddress VARCHAR2 | ||
) | ||
AS | ||
BEGIN | ||
UPDATE employees | ||
SET phone_number = v_phonenumber, | ||
email = v_emailaddress | ||
WHERE employee_id = v_emp_id; | ||
END; | ||
|
||
CALL UpdatePeopleContactDetails( | ||
v_emp_id => 207, | ||
v_phonenumber => '515.123.1111', | ||
v_emailaddress => 'BENBRUMM' | ||
); | ||
|
||
SELECT * | ||
FROM employees | ||
WHERE employee_id = 207; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE OR REPLACE PROCEDURE DeleteEmployee( | ||
v_empid IN NUMBER | ||
) | ||
AS | ||
BEGIN | ||
DELETE FROM employees | ||
WHERE employee_id = v_empid; | ||
|
||
DBMS_OUTPUT.PUT_LINE('Employee ID ' || v_empid || ' deleted.'); | ||
END; | ||
|
||
CALL DeleteEmployee(207); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CALL FindEmployeeName(102); | ||
|
||
DECLARE | ||
found_first_name VARCHAR2(100); | ||
BEGIN | ||
FindEmployeeName(101, found_first_name); | ||
DBMS_OUTPUT.PUT_LINE(found_first_name); | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE OR REPLACE PROCEDURE FindEmployeeName( | ||
v_employee_id IN NUMBER, | ||
v_first_name OUT VARCHAR | ||
) | ||
AS | ||
BEGIN | ||
SELECT first_name | ||
INTO v_first_name | ||
FROM employees | ||
WHERE employee_id = v_employee_id; | ||
|
||
END; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
CREATE OR REPLACE PROCEDURE ShowEmployeesHiredInRange( | ||
v_startdate IN DATE, | ||
v_enddate IN DATE | ||
) | ||
AS | ||
v_empid NUMBER; | ||
v_firstname VARCHAR2(100); | ||
v_lastname VARCHAR2(100); | ||
v_hiredate DATE; | ||
BEGIN | ||
SELECT employee_id, first_name, last_name, hire_date | ||
INTO v_empid, v_firstname, v_lastname, v_hiredate | ||
FROM employees | ||
WHERE hire_date BETWEEN v_startdate AND v_enddate | ||
FETCH FIRST 1 ROWS ONLY; | ||
|
||
DBMS_OUTPUT.PUT_LINE('Employee ' || v_empid || ' ' || | ||
v_firstname || ' ' || v_lastname || ' was hired on ' || | ||
v_hiredate); | ||
END; | ||
|
||
|
||
CALL ShowEmployeesHiredInRange( | ||
v_startdate => DATE'2005-01-01', | ||
v_enddate => DATE'2006-12-13' | ||
); | ||
|
||
|
||
/* | ||
Add IF | ||
*/ | ||
|
||
CREATE OR REPLACE PROCEDURE ShowEmployeesHiredInRange( | ||
v_startdate IN DATE, | ||
v_enddate IN DATE | ||
) | ||
AS | ||
v_empid NUMBER; | ||
v_firstname VARCHAR2(100); | ||
v_lastname VARCHAR2(100); | ||
v_hiredate DATE; | ||
BEGIN | ||
IF v_startdate > v_enddate THEN | ||
DBMS_OUTPUT.PUT_LINE('Invalid entry: the start date is after the end date.'); | ||
ELSE | ||
SELECT employee_id, first_name, last_name, hire_date | ||
INTO v_empid, v_firstname, v_lastname, v_hiredate | ||
FROM employees | ||
WHERE hire_date BETWEEN v_startdate AND v_enddate | ||
FETCH FIRST 1 ROWS ONLY; | ||
|
||
DBMS_OUTPUT.PUT_LINE('Employee ' || v_empid || ' ' || | ||
v_firstname || ' ' || v_lastname || ' was hired on ' || | ||
v_hiredate); | ||
END IF; | ||
END; | ||
|
||
|
||
CALL ShowEmployeesHiredInRange( | ||
v_startdate => DATE'2005-01-01', | ||
v_enddate => DATE'2006-12-13' | ||
); | ||
|
||
|
||
CALL ShowEmployeesHiredInRange( | ||
v_startdate => DATE'2008-01-01', | ||
v_enddate => DATE'2006-12-13' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE OR REPLACE PROCEDURE ListHelloBasic | ||
AS | ||
v_loop_counter NUMBER; | ||
BEGIN | ||
v_loop_counter := 1; | ||
LOOP | ||
DBMS_OUTPUT.PUT_LINE('Hello'); | ||
v_loop_counter := v_loop_counter + 1; | ||
|
||
IF (v_loop_counter > 10) THEN | ||
EXIT; | ||
END IF; | ||
END LOOP; | ||
END; | ||
|
||
CALL ListHelloBasic(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
SELECT * | ||
FROM locations; | ||
|
||
CREATE OR REPLACE PROCEDURE InsertLocations | ||
AS | ||
v_loop_counter NUMBER; | ||
BEGIN | ||
LOOP | ||
INSERT INTO locations (location_id, street_address, postal_code, | ||
city, state_province, country_id) | ||
VALUES (locations_seq.nextval, 'Temp Address', 12345, | ||
'Sydney', 'New South Wales', 'AU'); | ||
|
||
v_loop_counter := v_loop_counter + 1; | ||
|
||
IF (v_loop_counter > 4) THEN | ||
EXIT; | ||
END IF; | ||
END LOOP; | ||
END; |