Hi,
I'm building a simple form in HTML for users to use to query the database (ora 9i).The initial version of the HTML form has got 4 input fields.
City (default value is all cities)
Category (such as OLD or NEW vehicles. Default value is BOTH)
minimum_price (default value is no preference)
max_price (default value is no preference)
The problem I have comes to generating the query string for the user input.
I have a PL/SQL procedure that take all values from my HTML form but I just can't get the logic in
my procedure to work in terms of generating the WHERE clause and the 'AND' operators. I'm always ending up with an 'AND' operator too much. They way I'm trying to write my sql query is:
If the user only choose to select a particular city and leaving the other options intact. The SQL query should be something like
SELECT * FROM view_searchresult WHERE city = in_city;
On the other hand if the user choose to run a query where he/she searches on a particular City and Category the SQL query should be written like this
SELECT * FROM view_serachresult WHERE city = in_city AND category = in_category;
The way Im ending up writing my code seem to be very complicated and probably also inefficient.
Any help would be much appreciated
Erik
I'm building a simple form in HTML for users to use to query the database (ora 9i).The initial version of the HTML form has got 4 input fields.
City (default value is all cities)
Category (such as OLD or NEW vehicles. Default value is BOTH)
minimum_price (default value is no preference)
max_price (default value is no preference)
The problem I have comes to generating the query string for the user input.
I have a PL/SQL procedure that take all values from my HTML form but I just can't get the logic in
my procedure to work in terms of generating the WHERE clause and the 'AND' operators. I'm always ending up with an 'AND' operator too much. They way I'm trying to write my sql query is:
If the user only choose to select a particular city and leaving the other options intact. The SQL query should be something like
SELECT * FROM view_searchresult WHERE city = in_city;
On the other hand if the user choose to run a query where he/she searches on a particular City and Category the SQL query should be written like this
SELECT * FROM view_serachresult WHERE city = in_city AND category = in_category;
The way Im ending up writing my code seem to be very complicated and probably also inefficient.
Any help would be much appreciated
Erik