select statement base on user input
I have question about the sql statement to pass in the value into the where clause from the user input.
in the user input screen, I have drop down box to select a value for a particular table. 10,20,30 and *
for example : scott.dept table I have deptno 10,20,30
if the user select '*', my sql satetment will 'intelligently' detect it needs all the 10,20,30 value for the deptno. If the user only select 10, it only select dept= 10, and so on.
Question is how to put it into a single sql select statement with such condition ? or the application level has to auto convert the '*' to '10,20,30'....??
Ok! I got the solution from one of friend in Internet.
select * from emp
where deptno in (decode('&dept_value','*',10),
U can try this simple sql
select * from DEPT
where (DEPT_CODE = &P_DEPT_CODE OR
&P_DEPT_CODE = '*')
Hope this can help u
Click Here to Expand Forum to Full Width