Beruflich Dokumente
Kultur Dokumente
Question: In Oracle, I have a table called "wine" and a stored procedure that outputs a cursor based on the "wine" table. I've created an HTML Form where the user can enter any combination of three values to retrieve results from the "wine" table. My problem is that I need a general "select" statement that will work no matter what value(s), the user enters. Example: parameter_1= "Chianti" parameter_2= "10" parameter_3= wasn't entered by the user but I have to use in the select statement. And this is my problem. How to initialize this parameter to get all rows for column3? SELECT * FROM wine WHERE column1 = parameter_1 AND column2 = parameter_2 AND column3 = parameter_3;. The output of my stored procedure must be a cursor. Answer: To solve your problem, you will need to output a dynamic PLSQL cursor in Oracle. Let's take a look at how we can do this. We've divided this process into 3 steps.
select * from wine where wine.col1 = col1_in and wine.col2 = col2_in; /* col1 and col3 were entered */ ELSIF (length(col1_in) > 0) and (length(col2_in) = 0) and (length(col3_in) > 0) THEN OPEN c1 FOR select * from wine where wine.col1 = col1_in and wine.col3 = col3_in; /* col2 and col3 where entered */ ELSIF (length(col1_in) = 0) and (length(col2_in) > 0) and (length(col3_in) > 0) THEN OPEN c1 FOR select * from wine where wine.col2 = col2_in and wine.col3 = col3_in; /* col1 was entered */ ELSIF (length(col1_in) > 0) and (length(col2_in) = 0) and (length(col3_in) = 0) THEN OPEN c1 FOR select * from wine where wine.col1 = col1_in; /* col2 was entered */ ELSIF (length(col1_in) = 0) and (length(col2_in) > 0) and (length(col3_in) = 0) THEN OPEN c1 FOR select * from wine where wine.col2 = col2_in; /* col3 was entered */ ELSIF (length(col1_in) = 0) and (length(col2_in) = 0) and (length(col3_in) > 0) THEN OPEN c1 FOR select * from wine where wine.col3 = col3_in;