Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PLS-00330: invalid use of type name or subtype name

930814Apr 16 2012 — edited Apr 16 2012
I am relatively new to Sql and am in the process of learning, so please bear with me. I am trying to create a trigger for the Invoices table that displays the vendor_name, invoice_number, and payment_total after the payment_total has been increased. I have discovered that I must use a compound trigger due to a mutating-table error and ended up with this:
CREATE OR REPLACE TRIGGER invoices_after_update_payment
FOR UPDATE OF payment_total
ON invoices
COMPOUND TRIGGER
  TYPE invoice_numbers_table      IS TABLE OF VARCHAR2(50);
  TYPE payment_totals_table       IS TABLE OF NUMBER;
  TYPE vendor_names_table         IS TABLE OF VARCHAR2(50);
  TYPE summary_payments_table     IS TABLE OF NUMBER INDEX BY VARCHAR2(50);
  TYPE summary_names_table        IS TABLE OF NUMBER INDEX BY VARCHAR2(50);
  
  invoice_numbers                 invoice_numbers_table;
  payment_totals                  payment_totals_table;
  vendor_names                    vendor_names_table;
  payment_summarys                summary_payments_table;
  name_summarys                   summary_names_table;

  AFTER STATEMENT IS
    invoice_number VARCHAR2(50);
    payment_total NUMBER;
    vendor_name VARCHAR2(50);
  BEGIN
    SELECT i.invoice_number, i.payment_total, v.vendor_name
    BULK COLLECT INTO invoice_numbers, payment_totals, vendor_names
    FROM invoices i JOIN vendors v
      ON i.vendor_id = v.vendor_id
    GROUP BY i.invoice_number;
    
    FOR i IN 1..invoice_numbers.COUNT() LOOP
      invoice_number := invoice_numbers(i);
      payment_total := payment_totals(i);
      vendor_name := vendor_names(i);
      summary_payments_table(invoice_number) := payment_total;
      summary_names_table(invoice_number) := vendor_name;
    END LOOP;
  END AFTER STATEMENT;
  
  AFTER EACH ROW IS
    temp_payment_total NUMBER;
    vendor_name VARCHAR2(50);
  BEGIN
    temp_payment_total := payment_summarys(:new.invoice_number);
    vendor_name := name_summarys(:new.invoice_number);
    IF (:new.payment_total > temp_payment_total) THEN
      DBMS_OUTPUT.PUT_LINE('Vendor Name: ' || vendor_name || ', Invoice Number: ' || :new.invoice_number || ', Payment Total: ' || :new.payment_total);
    END IF;
  END AFTER EACH ROW;
END;
/
The code that I am using to update the table is:
UPDATE invoices
SET payment_total = 508
WHERE invoice_number = 'QP58872'
At this point, I am getting an error report saying:
29/7           PLS-00330: invalid use of type name or subtype name
29/7           PL/SQL: Statement ignored
30/7           PLS-00330: invalid use of type name or subtype name
30/7           PL/SQL: Statement ignored
What does the error code entail? I have looked it up but can't seem to pin it. Any help would be greatly appreciated and I am open to any suggestions for improving my current code.

I am using Oracle Database 11g Express Edition on Windows 7. I am not sure if it is relevant, but I am also using Sql Developer. If you need any further information, I will do my best to provide what I can.

Thanks!

Edited by: 927811 on Apr 15, 2012 11:54 PM

Edited by: 927811 on Apr 15, 2012 11:56 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2012
Added on Apr 16 2012
9 comments
7,879 views