You are on page 1of 1

Greetings, my name is Sim Kah Hoe. My student id is 2106036.

Now I will present my


individual part for this assignment.

1. For the first query I created it to count the total amount due for bills with
Patient Name. This is all the relevant codes to get the results we desired. To get
the total amount due we need to sum up all the bill and minus it with the total
payment paid. Since sum is a group function we will need to use the Group By.

2. 2nd query is display all the admited patients' full name , ward number and bed
number. This can be done by joining person table with consulatation then join it to
admission. This will link them together thus giving access to the patient's name,
bed_number and ward_number.

3. Now moving on to the stored procedure. The first one is to add specialist. To
make this work make sure they accepts these paramters and insert it into the person
table.

EXECUTE add_specialist('John', 'Doe', '04-APR-83', '123 Main St', '555-1234', 'M',


1);

4. Then is the update_specialist procedure. This almost the same as before where we
make sure it accept these paramters, the difference is we can now input a number
infront of the details to indicate who we want to change, then it will update the
existing value.

EXECUTE update_specialist(11, 'Jason', 'Doe', '04-APR-83', '123 Main St', '555-


1234', 'M',1);

5. This function calculates the total due for all persons. It starts by declaring
the variable total_due of type number. Then it performs a query that join person
table with bill on person_id and p_id. And finally sum the total bill amount.

SELECT calculate_total_due_func() as Total_Due FROM dual;

6. This function return system_refcursor then the function executes select


statement to join the necessary tables. The loop is used to fetch statemens
retrieves the next row of data from the admission_cursor.

SELECT p.first_name || ' ' || p.last_name AS "Patient Name", COUNT(*) AS "Number


of Admissions"
FROM person p
JOIN consultation c ON p.person_id = c.p_id
JOIN admission a ON c.consultation_id = a.consultation_id
GROUP BY p.first_name, p.last_name;

You might also like