关于如何在Oracle Express-SQL中创建。触发更新列

时间:2018-12-31 14:19:28

标签: sql oracle triggers

我有一个product表和一个sales表。在product内,我有(product_id, p_desc, qty_stock),在sales表中,我有(sale_id, producto_id, sale_p_qty),其中sale_p_qty是客户从某种产品购买的数量。

问题是我该如何触发更新qty_stock表中的product列值(该值将是库存)?我做不到。我可以创建一个递减的触发器,但一次只能一个值。正确的方法是获取表sale_p_qty的{​​{1}}并在sales中递减,但我不能这样做。你能帮我一下吗?

我的尝试到此为止(我没有执行任何步骤,在这种情况下我不知道您是否需要这样做):

qty_stock

1 个答案:

答案 0 :(得分:0)

您可以分两个步骤进行操作:

déc. 31, 2018 3:04:14 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: c199c628-c3c8-4850-8252-9446b6c90cab Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:14 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: f468dbd4-f340-4e6a-a6ab-103350c3a547 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:14 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 8c96557e-88a6-4745-a1c6-f839bfc44142 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:15 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 2987d710-3007-47a9-bfaa-2573c79ef049 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:15 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: f5f84cb6-33ac-4dc7-a500-cdb957470d01 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:16 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: f7eaa8cc-0a65-455b-bc8d-df64b18f0532 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:17 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: a223c4aa-f1c6-47c4-b40c-1d39a5a03db0 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:18 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: d822a2b8-8387-43ba-a814-6dade9f71e5f Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:19 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: d152a753-708b-4bcb-aa2e-87b5346911df Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:20 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 1dba43a1-e6e3-4dc7-9707-42ba909a30aa Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:21 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 193ee01c-f0b8-4e0c-8e06-77f4bde7ef5c Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:22 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 34a6c52e-bbad-44a5-a4c3-acb712bf7a2a Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:23 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: 4bbfa516-99db-49bc-8648-657627b3010d Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:24 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: ea3649d5-1adc-4dd4-a340-a2d0d95e8af3 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:25 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: ad4d76d7-77ca-4686-ab2a-3f802f36d533 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:26 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: bbaa643f-1b0c-4d92-b5ff-81efb1f09a83 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
déc. 31, 2018 3:04:27 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin AVERTISSEMENT: ConnectionID:1 ClientConnectionId: dcbff2e2-1673-435e-b1a8-de5ea610fc77 Prelogin error: host 192.168.10.97 port 1433 Unexpected end of prelogin response after 0 bytes read
com.microsoft.sqlserver.jdbc.SQLServerException: Échec de la connexion TCP/IP à l'hôte 192.168.10.97, port 1433. Erreur : « Le pilote a reçu une réponse de préconnexion inattendue. Examinez les propriétés de connexion et vérifiez qu'une instance de SQL Server est en cours d'exécution sur l'hôte et accepte les connexions TCP/IP au port. Ce pilote peut être utilisé uniquement avec SQL Server 2005 ou ultérieur. ». ClientConnectionId:dcbff2e2-1673-435e-b1a8-de5ea610fc77

即使CREATE OR REPLACE TRIGGER trg_stock_ai AFTER INSERT OR UPDATE ON sale FOR EACH ROW BEGIN UPDATE product SET qty_stock = (qty_stock - :NEW.sale_p_qty) WHERE p.product_id = :NEW.product_id; UPDATE product SET qty_stock = (qty_stock + :OLD.sale_p_qty) WHERE p.product_id = :OLD.product_id; END; 发生更改,这也应适用于插入和更新。