0
votes

This is what I need to accomplish: Create a TRIGGER named tgr_customer_insert that will fire AFTER a row is inserted into the customers table. The trigger can be created after you create the cardholder table, so it can be in the same ps16a.sql file just created. This trigger will insert a row into the cardholder table when a row is inserted into the temp_table_customers table. Here are the columns to insert: card_number (this is inserted using the seq_cardholder sequence number) customer_id (this is a bind variable from the temp_table_customer table using the :new.column_name syntax) credit_limit (this is a bind variable from the temp_table_customer table using the :new.column_name syntax)

This is my code:

`CREATE OR REPLACE TRIGGER tgr_customer_insert
AFTER INSERT
   ON customers
   FOR EACH ROW
BEGIN
   -- Insert record into customers table
   INSERT INTO cardholder
   ( card_number,
     customer_id,
     credit_limit
   )
   VALUES
   ( new.seq_cardholder,
     :new.customer_id,
     :new.credit_limit
   );
END;

`

Error is: ORA-24344: success with compilation error Line 3 Position 4.

Hair is being torn out. Thank you in advance for you time with this matter.

1
Detail on error is: PL/SQL: SQL Statement ignored - Flash_Jordan
Use show errors to get the full error message - a_horse_with_no_name

1 Answers

0
votes

I think you are missing a ':' in INSERT VALUES for first value binding.

CREATE OR REPLACE TRIGGER tgr_customer_insert
AFTER INSERT
   ON customers
   FOR EACH ROW
BEGIN
   -- Insert record into customers table
   INSERT INTO cardholder
   ( card_number,
     customer_id,
     credit_limit
   )
   VALUES
   ( :new.seq_cardholder,
     :new.customer_id,
     :new.credit_limit
   );
END;

If, "seq_cardholder" is a sequence then you have to use as below:

CREATE OR REPLACE TRIGGER tgr_customer_insert
AFTER INSERT
   ON customers
   FOR EACH ROW
BEGIN
   -- Insert record into customers table
   INSERT INTO cardholder
   ( card_number,
     customer_id,
     credit_limit
   )
   VALUES
   ( seq_cardholder.nextval,
     :new.customer_id,
     :new.credit_limit
   );
END;