Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m basically trying to use PL/SQL to retrieve all the rows where the balance d

ID: 3537934 • Letter: I

Question

I'm basically trying to use PL/SQL to retrieve all the rows where the balance due for some vendors is greater than 5000.


My code looks like this:


SET SERVEROUTPUT ON

--dbms_output.put_line('string');
DECLARE
CURSOR countoccur IS
    SELECT invoice_total, payment_total, credit_total
    FROM invoices
    WHERE (invoice_total - payment_total - credit_total) >= 5000;
BEGIN
dbms_output.put_line( countoccur );
END;
/


I know that the SELECT... FROM... WHERE clauses are correct as I have verified this in a separate worksheet, and the result is 3 rows. My BEGIN/END statements are also correct, because I know that if I substituted countoccur with some string, it would print out the string; also, the CURSOR declaration part is correct, and yet if I expect countoccur to act as a variable (whose number I expect to be 3) I apparently cannot print it in the BEGIN/END statement as I have defined above.


What do I change?

Explanation / Answer

The problem was with BEGIN. Correct code:


SET SERVEROUTPUT ON

--dbms_output.put_line('string');
DECLARE
CURSOR countoccur IS;

BEGIN
    SELECT invoice_total, payment_total, credit_total
    FROM invoices
    WHERE (invoice_total - payment_total - credit_total) >= 5000;
dbms_output.put_line( countoccur );
END;
/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote