Hi,
I am making a small application in PL/SQL for handling ordering of movietickets at a cinema (i am a newbie to this). When you enter your wish for what seat on which row you want among available seats, the program does the rest by registering your information into the database. BUT if you do not enter any value for seat and row - a procedure is to find the best combination of a seat and a row in the showroom.
This is what I have done:
finding max value for row and seat, then putting the values into a random select like:
SELECT round(dbms_random.value(seat_min, seat_max),0)
into x_seat
from dual;
SELECT round(dbms_random.value(row_min, row_max),0)
into x_row
from dual;
I then take the x_seat and x_row and puts them in a select statement that finds a valid combination of a seat and row. All this is in a loop that exit when the output of the select statement has value >=1 for seat and row.
But this only works sometimes. Acationally it returns with the exception no_data_found. So this is not a good way of resolving this.
So, how can I find the best available combination of a seat and a row in a showroom of a cinema? I assume it has to be in the middle. For example if you have:
seat 1 on row 1
seat 2 on row 1
seat 3 on row 1
seat 1 on row 2
seat 2 on row 2
seat 3 on row 2
seat 1 on row 3
seat 2 on row 3
seat 3 on row 3
the best combination is seat 2 on row 2 if the seat is available and not taken... How do I do this? I need serious help.. Thanks!
I am making a small application in PL/SQL for handling ordering of movietickets at a cinema (i am a newbie to this). When you enter your wish for what seat on which row you want among available seats, the program does the rest by registering your information into the database. BUT if you do not enter any value for seat and row - a procedure is to find the best combination of a seat and a row in the showroom.
This is what I have done:
finding max value for row and seat, then putting the values into a random select like:
SELECT round(dbms_random.value(seat_min, seat_max),0)
into x_seat
from dual;
SELECT round(dbms_random.value(row_min, row_max),0)
into x_row
from dual;
I then take the x_seat and x_row and puts them in a select statement that finds a valid combination of a seat and row. All this is in a loop that exit when the output of the select statement has value >=1 for seat and row.
But this only works sometimes. Acationally it returns with the exception no_data_found. So this is not a good way of resolving this.
So, how can I find the best available combination of a seat and a row in a showroom of a cinema? I assume it has to be in the middle. For example if you have:
seat 1 on row 1
seat 2 on row 1
seat 3 on row 1
seat 1 on row 2
seat 2 on row 2
seat 3 on row 2
seat 1 on row 3
seat 2 on row 3
seat 3 on row 3
the best combination is seat 2 on row 2 if the seat is available and not taken... How do I do this? I need serious help.. Thanks!