How can I do this dynamical update in Oracle?

时间秒杀一切 提交于 2019-12-24 22:35:33

问题


I have the model table defined like:

MODEL (id NUMBER, capacity NUMBER ) 

and the flight table defined like:

FLIGHT (flight_number NUMBER, available_seats NUMBER)

I want to initialize the available_seats field in FLIGHT with the capacity number defined in MODEL each time a new row is inserted in FLIGHT table. Also I want to notify the user when the available_seats counts down to zero. How can I do this?


回答1:


I would write a stored procedure called REGISTER FLIGHT, which would accept as parameters the PK of the MODEL table (and any other parameters needed. The have the procedure do the lookup on the MODEL table, and insert the initial rows into the flight table.

I would then have a second procedure called BOOK_SEAT, which would in the process of booking the flight, decrease the number of available seats in the flight. If the booking decreases the available_seats to zero (or fewer), it would throw an exception (e.g. OVERBOOKED_EXCEPTION) and expect the caller to catch and handle the problem.



来源:https://stackoverflow.com/questions/4703040/how-can-i-do-this-dynamical-update-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!