-- between 연산자
select ename, sal
from EMP
where sal >= 2000 and sal <= 3000; -- sal이 2000이상 3000이하를 나타내라.

select ename, sal
from EMP -- between And B 연산자 : 실행하면 부등호 형식으로 다시 바뀌니 부등호로 하는게 실행이 빠르다.
where sal between 2000 and 3000;  -- between 연산자는 숫자 , 문자 모두 가능하다.

select ename, sal
from EMP
where ename >= 'J' and ename <= 'S'; -- ename의 값이 J에서 S사이값을 나타낸다.
where ename >= 'j' and ename <= 's'; -- 이경우는 값이 출력되지 않는다. 아스키값을 확인하면 이해하기 쉽다.

select ascii('A'), ascii('a') from dual; -- 아스키값 출력

select ename, hiredate
from EMP
where hiredate >= '1982' and hiredate <= '1987'; -- 문자 형식이라 오류가 뜬다. 다음을 참조한다.

select sysdate, to_char(sysdate, 'yyyy') -- sysdate에서 문자형식으로 추출한다.
from dual;

select sysdate, extract(year from sysdate) -- sysdate에서 원하는 부분을 숫자 형식으로 추출한다.
from dual;

select ename, hiredate
from EMP
where to_char(hiredate, 'yyyy') >= '1982' and
   to_char(hiredate, 'yyyy') <= '1987';    -- 날짜값에서 원하는 부분 문자형식으로 
  
select ename, hiredate
from EMP
where extract(year from hiredate) >= '1982' and
   extract(year from hiredate) <= '1987';  -- 날짜값에서 원하는 부분을 숫자형식으로
  
select ename, hiredate
from EMP
where to_char(hiredate, 'yyyy') between 1982 and 1987; -- to_char 와 between 동시사용

select ename, hiredate
from EMP
where extract(year from hiredate) between 1982 and 1987; -- extract 와 between 동시사용

'Program... > Oracle' 카테고리의 다른 글

Oracle LIKE 연산자  (0) 2009.03.13
Oracle IN 연산자  (0) 2009.03.13
Oracle 날짜 표시  (0) 2009.03.13
Oracle 비교연산자  (0) 2009.03.13
Oracle 중복행 제거  (0) 2009.03.13
Posted by Duritz

공지사항

Yesterday
Today
Total
05-06 03:14

달력

 « |  » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31