简体   繁体   中英

Creating Oracle SQL Trigger Error

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM