AND, OR, NOT, BETWEEN, IN
조건> mgr이 7800이상이고 job이 MANAGER인 데이터추출
select * from emp
where mgr>=7800 ans job='MANAGER'
조건> 부서가 10번 이거나 직급이 MANAGER인 자료를 추출
select * from emp
where deptno=10 or job='MANAGER'
select * from emp where not deptno=10
select * from emp where deptno<>10
select * from emp where comm is null; //null은 is로 뽑는다.
select * from emp where comm is not null;
select last_name, job_id, salary from employees where job_id='SA_REP' or job_id='AD_PRES' and salary>1500
select last_name, job_id, salary from employees where (job_id='SA_REP' or job_id='AD_PRES') and salary>1500
and가 or보다 우선순위가 높다(따라서 괄호사용)
조건>2000에서 3000사이
selec last_name, job_id, salary from employees where salary>=2000 and salary<=3000;
selec last_name, job_id, salary from employees where salary between 2000 and 3000;
select * from emplyees where commission_pct =0.2 or commission_pct=0.3 or commssion_pct=0.4;
//or너무 김..in연산자 사용
select * from emplyees where commission_pct in(0.2,0.3,0.4);
직책이 SH_CLERK이거나 SA_REP인 자료중에서 salary가 10000이상인 추출하세요(IN연산자 이용해서)
select first_name,last_name,job_id, salary from employees where (job_id='SH_CLERK'or job_id='SA_REP') and salary>=11000;
select first_name,last_name,job_id, salary from employees where job_id in('SH_CLERK','SA_REP') and salary>=11000;
*In연산자는 와일드카드(%,_)와 함께 사용할 수 없다. - 일치되는 값으로 사용해야 함
select first_name,salary, from employees where salary between 2000 and 3000;
select first_name,salary, from employees where salary between 3000 and 2000;
//값이 다름: 앞에는 작은값에서 and 뒤 큰값으로 적어주어야 정확한 값이 나온다.
not은 연산자앞에 not만 붙여주면 부정의 연산자가 된다.
select * from emp where comm not in(300,500,1400);
테이블생성
create table t1
(name varchar2(10)); //t1이라는 테이블안에 name이라는 컬럼생성(varchar(10))
insert into t1 values ('AAA');
만일 A_B라는 값을 검색할때 _는 like구문에서 어떻게 인식할것인가? ->escape
select * from t1 where name like 'A!_%' escape '!'; //escape '문자로 인식할 문자' escape문자 다음문자만 문자로 인식하고 그다음부터는 와일드카드가 있을 경우 와일드카드로 인식함.
NULL - > undifined
select employee_id, first_name from employees whㅓㅇere employee_id=(&empvar);
select employee_id, first_name from employees where employee_id=&enp;
※버퍼를 초기에 생성하고 바로 실행하는 방법!
ed a001.sql(형식:ed 파일명)->버퍼 초기생성
exit한후 dir확인해도 되지만 다시접속해야하는 번거로움으로 인해 바로 host를 실행해서 디렉토리를 확인한다.
host ->sql접근에서 dos창으로 빠져나오는 명령, dir->파일이나 디렉토리 확인
exit->다시 sql로 컴백(수동연결하지 않아도 자동으로 연결이 가능함)
@001(형식:@파일명) 입력하면 ed a001.sql에 저장된 명령어기능을 수행한다.
---------------------
※쿼리문 생성하고 바로 파일(버퍼아님)에 저장하는 방법!
select * from employees;
*아래에 명령을 수행해주기 위해서는 반드시 미리 명령어를 수행해야 한다.
save 003 (형식:save 파일명):쿼리문 자동저장
save 003 replace (형식:save 파일명 replace):저장되있는 파일을 지우고 다시 저장함
save 003 append(형식 save 파일명 append):이전쿼리문을 손상시키지 않고 기존에 쿼리에 추가해서 저장
위에는 버퍼에 저장되는 것이 아닌 파일에 저장하는 방식이다.
해당 파일의 내용을 퍼버에 저장하고 싶은경우 get을 사용하면된다.
칼럼이 숫자인 경우 숫자 대한 형식을 지정해주는것
column salary format 9,999,999; (column 컬럼명 format 원하는 형식)
만약 0,000,000은 자료를 0으로 채워서 보내주는 반명 9는 해당숫자의 자리값이 없으면 생략해 준다.
오름차순/내림차순
select first_name, last_name, salary from employees order by salary desc; //내림차순
select first_name, last_name, salary from employees order by salary //오름차순 , asc써줘도 됨
select empno, job from emp order by sal where job='SALESMAN' //이러면 오류남. order by는 무조건 맨 뒤에 위치시켜주세요 ~
order by 학년,반 ->학년 오름차순 정렬하고 그다음에 같은 학년중 반을 오름차순정렬
order by 학년,반 desc->학년 오름차순 정렬하고 다음에 같은 학년중 반을 내림차순정렬
'Oracle > Oracle' 카테고리의 다른 글
Oracle 5 (3) | 2012.04.02 |
---|---|
Oracle 4 (0) | 2012.03.30 |
Oracle 3 (0) | 2012.03.29 |
Oracle 2-2 (0) | 2012.03.28 |
Oracle 정리 Start (1) | 2012.03.27 |