목록kitri 노트/oracle (10)
기록 저장소
[ 데이터 조작어(DML) ]1. 데이터 갱신1) INSERT (3) subquery를 이용한 insert → value 자리에 query 문으로 값을 가져옴 ▷ 예제-- ex1) 부서아이디가 80번인 사원의 정보를 emp_blank 테이블에 입력insert into emp_blankselect *from employeeswhere department_id = 80; -- ex2) 100번 사원의 사번, 이름, 직책, 부서번호를 emp_blank 테이블에 입력insert into emp_blank (employee_id, first_name, last_name, email, hire_date, job_id, department_id)select employee_id, first_name, last_nam..
[ 데이터 정의어 (DDL) ] * Data Definition Language 객체(Schema, Domain, Table, View, Index)를 정의, 변경 또는 삭제할 때 사용하는 언어 → CREATE / DROP / ALTER / * ksc5601 == euc - kr >> 한글: 2byte, 영어/숫자: 1byte >> 한글의 경우 char: 최대 1000자, vc2: 최대 2000자* utf-8 >> 한글: 3byte, 영어/숫자: 1byte >> 한글의 경우 char: 최대 666자, vc2: 최대 1333자 1. 데이터 속성(Type) 1) 숫자형 ▷ number [(n, m)]- n은 자릿수, m은 소수 이하 자릿수- n은 소수점 이하 자릿수를 포함한 전체 자릿수- m의 default..
[ JOIN과 Subquery ] 3. 집합(Set) 연산자 1) Union : 두 질의 결과값의 합에서 중복을 제거 → 합집합 -- 부서번호가 50이거나 90인 사원과-- 급여가 10000 이상인 사원의-- 사번, 이름, 급여, 부서번호select employee_id, first_name, salary, department_idfrom employeeswhere department_id in (50, 90)union select employee_id, first_name, salary, department_idfrom employeeswhere salary >= 10000; 2) Union all : 두 질의 결과값의 합에서 중복을 포함 → 합집합 + 교집합 select employee_id, fir..
[ JOIN과 Subquery ] 2. Subquery : Subquery는 다른 하나의 SQL 문장의 절에 NESTEDED된 SELECT 문장. Main query보다 먼저 실행됨 * select 절, from 절, where 절, order by 절, insert....... 모두에 사용 가능함 (다만, 실무상 order by 절에는 거의 사용하지 않음) 1) where 절의 subquery (1) 기본 문법 ▷ Subquery의 필요성 select e.employee_id, e.first_name, e.salaryfrom departments d, employees ewhere d.department_id = e.department_id -- catesian product에서 조건을 검색하므로, 효..
[ JOIN과 SubQuery ] 1. JOIN 4) Non-Equi Join : equal condition 이외의 비교연산자에 의한 join * 테이블의 어떤 컬럼도 join할 테이블의 컬럼에 일치하지 않을 때 사용 -- 모든 사원의 사번, 이름, 급여, 급여등급select e.employee_id, e.first_name, e.salary, g.grade_levelfrom employees e, job_grades gwhere e.salary between g.lowest_sal and g.highest_salorder by e.salary desc; 5) Outer Join : 동일 조건에서 조인 조건을 만족하는 값이 없는 row를 조회하기 위해 사용 * equi join 에서만 사용?? - jo..
5. 일반 함수 3) decode ( char, a1, b1, a2, b2, ......., c ) : a 조건을 만족하면 b 반환. 만족하지 않으면 c(default value) 반환. - a, b의 개수는 가변(여러개 쓸 수 있음)- equal 비교만 가능함 (대소비교시에는 case 함수 사용) -- 사번, 이름, 부서번호, 직원유형-- 직원유형-- 부서번호 60 개발자-- 90 임원진-- 나머지 비개발자select employee_id 사번, first_name 이름, department_id 부서번호, decode(department_id, 60, '개발자', 90, '임원진', '비개발자') 직원유형from employees; [그룹 함수] group by는 나중에 배운다고함~~~ 일단 아래 것..
[단일행 함수] 1. 숫자 함수 * round 정도를 가장 빈번하게 사용함 1) round ( n, [m] ) : 반올림하여 m자리까지 반환. m은 소수점 아래 자릿수. (기본값은 0이며 1의 자리임) * 결국 m+1의 자리에서 반올림한다는 의미 -- roundselect 1234.5438, round(1234.5438) round1, round(1234.5438, 0) round2, round(1234.5438, 1) round3 , round(1234.5438, -1) round4, round(1234.5438, 3) round5, round(1234.5438, -3) round6from dual; -- 사원의 사번, 이름, 급여, 커미션포함급여-- 커미션 포함 급여는 100의 자리수로 표현(반올림)..
2)where : 참/거짓의 판별 조건문 (1) 비교연산자 : , =, =, -- 급여를 5000이상 받는 사원의 사번, 이름, 급여, 부서번호select employee_id, first_name, salary, department_idfrom employeeswhere salary >= 5000; - 는 != , ^= 를 사용할 수도 있음 -- 부서번호가 50이 아닌 사원의 사번, 이름, 부서번호select employee_id, first_name, department_idfrom employeeswhere department_id 50; select employee_id, first_name, department_idfrom employeeswhere department_id != 50; sele..