Monday, July 21, 2008

Create a Variable in SQLPLUS to Limit Query Results using a List

select * from dept where deptno in ( '10','20','30');
Now I want to declare one vaibale to hold that string let us say declare dept_string = '10','20','30'. Create variable as follows,
define dept_string = '(''10'',''20'',''30'')';
OR
define dept_string = "('10','20','30')";
select * from dept where deptno in &deptno
The above query will give the desired result.

No comments:

search engine

Custom Search