0

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.

2
  • Detail on error is: PL/SQL: SQL Statement ignored Commented May 15, 2018 at 3:26
  • Use show errors to get the full error message Commented May 15, 2018 at 5:48

1 Answer 1

0

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;
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that before posting but I get: ORA-24344: success with compilation error
More details show: PLS-00049: bad bind variable 'NEW.SEQ_CARDHOLDER'
Nevermind, you are correct. It is a sequence that I created and your code created the trigger successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.