【发布时间】:2018-07-20 20:20:17
【问题描述】:
场景如下-
- 包含“OrderId”和“OrderType”列的OrderTable
- 包含“OrderId”和“CustId”列的OrderRelationTable
- OrderProcessTable 包含“OrderId”、“OrderType”、“CustId”和“ProcessFlag”列
流程是这样的-
Application1 在 OrderTable 中创建记录 -> 然后使用 MQ 协议将记录传递给 Application2,在这种情况下,Application 2 插入/创建在 OrderRelationTable 中传递的记录 -> 然后在 Oracle DB 中调用触发器来创建记录在 OrderProcessTable 中
问题
有时记录没有插入到表 3 OrderProcessTable 中。不知道是时间问题还是触发器有问题?
Application1 代码
boolean updated = false;
/** JDBC prepare statement execution insert into OrderTable in Java**/
int rowCount = ps.executeUpdate();
if(rowCount>0){
updated=true;
}
log.log("updated flag:"+updated);
/** I am able to see the log shows the flag is true, and recored inserted into OrderTable **/
Application2 代码 假设它是一些 Java JDBC 代码插入 OrderRelationTable 并且它是成功的,这并不重要。
触发器
假设语法是正确的。
CREATE OR REPLACE TRIGGER INSERTINTOOrderProcessTable
AFTER INSERT ON OrderRelationTable
FOR EACH ROW DECLEAR
v_order_type := null;
BEGIN
SELECT OrderType INTO v_order_type FROM OrderTable
WHERE OrderId = :new.OrderId
AND OrderType IS NOT NULL
AND rownum=1;
IF v_order_type IS NOT NULL THEN
INSERT INTO OrderProcessTable VALUES (:new.OrderId, v_order_type, :new.CustId, 'N');
END IF;
END;
问题 -
- 应用程序 1 代码执行后保证 DB 将具有可用于 SELECT 语句的 OrderTable 记录? (假设更新标志为真)
- 应用代码和触发器是否存在计时问题?例如,当触发器从 OrderTable 调用 SELECT 语句时? (当然,OrderRelationTable 和 OrderTable 中的订单 id 是匹配的)
- 基本上现在我的问题是,有时(很少)记录没有通过触发器插入 OrderProcessTable,即使它应该(订单类型不为空)?有什么想法吗?
【问题讨论】:
-
你检查过 OrderTable 的 OrderType IS NULL 吗?
-
@P.Salmon 我检查了 OrderTable OrderType 不是 NULL。
标签: sql-server oracle triggers oracle-sqldeveloper