------------------- **** 비교연산자 **** -------------------
1. 같다 =
2. 같지않다 != <> ^=
3. 크다. 작다 > <
4. 같거나크다. 같거나작다 >= <=
5. NULL 은 존재하지 않는 것이므로 비교대상이 될 수가 없다.
그러므로 비교연산( = != <> ^= > < >= <= )을 할수가 없다.
그래서 비교연산을 하려면 nvl()함수, nvl2()함수를 사용하여 처리한다.
오라클에서 컬럼들을 붙일 때(연결할 때)는 문자타입이든, 숫자타입이든, 날짜타입이든 관계없이 || 를 사용한다.
-- EMPLOYEES 테이블에서 부서번호가 30번 인 직원들만 사원번호, 사원명, 월급, 부서번호를 추출하세요.
select employee_id 사원번호
, first_name || ' ' || last_name 사원명
, nvl( salary + (salary * commission_pct), salary ) 월급
, department_id 부서번호
from employees
where department_id = 30;
-- EMPLOYEES 테이블에서 부서번호가 30번이 아닌( !=, <>, ^= ) 직원들만 사원번호, 사원명, 월급, 부서번호를 추출하세요.
select employee_id 사원번호
, first_name || ' ' || last_name 사원명
, nvl( salary + (salary * commission_pct), salary ) 월급
, department_id 부서번호
from employees
-- where department_id != 30;
-- where department_id <> 30;
where department_id ^= 30; -- 그러나 null 은 안나옴
desc employees; -- null 값을 허락하는지 조회먼저 해봐야 함. !!중요!!
select employee_id 사원번호
, first_name || ' ' || last_name 사원명
, nvl( salary + (salary * commission_pct), salary ) 월급
, department_id 부서번호 -- 화면에 보여줄 때는 오리지널값으로 표시
from employees
where nvl( department_id, -9999) != 30;
-- EMPLOYEES 테이블에서 부서번호가 NULL이 아닌( !=, <>, ^= ) 직원들만 사원번호, 사원명, 월급, 부서번호를 추출하세요.
select employee_id 사원번호
, first_name || ' ' || last_name 사원명
, nvl( salary + (salary * commission_pct), salary ) 월급
, department_id 부서번호 -- 화면에 보여줄 때는 오리지널값으로 표시
from employees
where nvl( department_id, -9999) != -9999;
/* 또는
where department_id is not null;
또는
where not(department_id is null);
또는
where notdepartment_id is null;
*/
'SQL' 카테고리의 다른 글
1차 정렬, 2차 정렬 (0) | 2022.07.04 |
---|---|
오름차순정렬, 내림차순정렬 (0) | 2022.07.04 |
NVL, NVL2 (0) | 2022.07.04 |
데이터타입 (0) | 2022.07.04 |
select, from, describe, show (0) | 2022.07.04 |