简体   繁体   English

创建Oracle SQL触发器错误

[英]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. 这是我需要完成的任务:创建一个名为tgr_customer_insert的TRIGGER,该触发器将在客户表中插入一行后触发。 The trigger can be created after you create the cardholder table, so it can be in the same ps16a.sql file just created. 可以在创建持卡人表之后创建触发器,因此触发器可以位于刚创建的同一ps16a.sql文件中。 This trigger will insert a row into the cardholder table when a row is inserted into the temp_table_customers table. 当将行插入到temp_table_customers表中时,此触发器将在持卡人表中插入一行。 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) 以下是要插入的列:card_number(使用seq_cardholder序列号插入)customer_id(这是使用:new.column_name语法的temp_table_customer表的绑定变量)credit_limit(这是使用temp_table_customer表的绑定变量) :new.column_name语法)

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. 错误是:ORA-24344:成功,编译错误第3行位置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. 我认为您在INSERT VALUES中缺少第一个值绑定的“:”。

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: 如果“ seq_cardholder”是一个序列,则必须使用以下方法:

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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