hi
i want fillter A to K at ename in emp table
how is possible
Printable View
hi
i want fillter A to K at ename in emp table
how is possible
First create a table and insert letter into that table as follows
create table test(let char(1))
insert into test_let values('A')
insert into test_let values('B')
insert into test_let values('C')
insert into test_let values('D')
insert into test_let values('E')
insert into test_let values('F')
then write this simple query to get the result
select a.ename,a.job,a.sal
from emp a, test b
where ename like b.let||'%'
The following query works only if you are using oracle 9i or above version.
With test as
( select 'a' let from dual
union all
select 'b' let from dual
union all
select 'c' let from dual
union all
select 'e' let from dual
union all
select 'f' let from dual )
select a.ename,a.job,a.sal
from emp a , test b
where ename like b.let||'%';
can i use this method
select * from emp where ename between 'A' and 'M'
or
select * from emp where ename between 'A' and 'L'
union all
select * from emp where ename like 'L%'
or
select * from emp where ename > 'L'
union all
select * from emp where ename like 'L%'
[B]>>select * from emp where ename between 'A' and 'M'[/B]
Add substr function to the above query as follows
select * from emp
where substr(ename,1,1) between 'A' and 'M'
Generally between operator is used with numeric and date data types not with character data types.
[QUOTE=priyasp_msit;29951]hi
i want fillter A to K at ename in emp table
how is possible[/QUOTE]
SELECT ename
FROM emp
WHERE SUBSTR(ename,1,1) IN('A','B','C',-----------'K');
[QUOTE=chandra.pc;30270]SELECT ename
FROM emp
WHERE SUBSTR(ename,1,1) IN('A','B','C',-----------'K');[/QUOTE]
This will work ,but might be bit slow for large tables because of string operation and IN comparision.