-- IN (list) 연산자
select ename, job
from EMP
where job = 'SALESMAN' or
   job = 'CLERK' or
   job = 'MANAGER'; -- or 만으로만 구성 (권장사항)
  
select ename, job
from EMP
where job In ('SALESMAN', 'CLERK', 'MANAGER'); -- IN 연산자사용

select ename, job
from EMP
where not job In ('SALESMAN', 'CLERK', 'MANAGER'); -- IN연산자에서 부정사용

select ename, job
from EMP
where job ^= 'SALESMAN' and  -- 같지 않다의 의미인 ^= 사용
   job ^= 'CLERK' and     -- and는 or의 부정표현이다.
   job ^= 'MANAGER';

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

Oracle IS NULL 연산자  (0) 2009.03.13
Oracle LIKE 연산자  (0) 2009.03.13
Oracle Between 연산자  (0) 2009.03.13
Oracle 날짜 표시  (0) 2009.03.13
Oracle 비교연산자  (0) 2009.03.13
Posted by Duritz

-- 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

-- 날짜 표시
-- 윈도우기반은 (RR/MM/DD)로 표시되고, 유닉스 기반은 (MON-DD-RR)로 표시된다.
-- 따라서 원하는 형식으로 보기 위해서는 to_char()를 써서 원하는데로 변경한다.
select ename,
       to_char(hiredate, 'yyyy-mm-dd hh24:mi:ss') Hiredate -- to_cahr() 원하는 형식으로 표시한다.
from emp;

select dbtimezone, -- dbtimezone은 오라클을 만든 미국의 시간대 표시
       sessiontimezone -- sessiontimezone는 그리니치 천문시간대 기준으로본 한국 시간대
from dual;

select localtimestamp, --
       current_timestamp
from dual;

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

Oracle IN 연산자  (0) 2009.03.13
Oracle Between 연산자  (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-04 14:12

달력

 « |  » 2025.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