-- 테이블의 모든 데이터를 표현
SELECT * FROM EMP;
SELECT * FROM EMPLOYEES;
-- 테이블의 이름을 기록한 테이블 명세
SELECT * FROM tab;
-- 테이블에서 원하는 열(컬럼)만 표현
SELECT EMPNO, ename, SAL
FROM EMP;
SELECT ename
FROM emp;
-- dual : 가상테이블
SELECT sysdate FROM dual;
SELECT 10+2 FROM dual;
SELECT 'hello' FROM dual;
SELECT round(10.5) FROM dual;
SELECT ename, sal, sal + 300
FROM emp;
SELECT sal, sal * 12
FROM emp;
-- alias int ar[] = arr;
SELECT sal * 12 as Money, sal
FROM EMP;
-- 연결 연산자 || : 열이나 문자열을 다른 열에 연결
SELECT ENAME || ' has $' || SAL
FROM EMP;
-- distinct : 중복행을 삭제
SELECT DISTINCT DEPTNO
FROM EMP;
-- 테이블의 구조 표시
-- 컬럼을 표시
DESCRIBE EMP;
desc emp;
-- *WHERE* 절 == IF문
/*
표현식
비교 연산자( = < > != >= <= <> )
NULL, IS NULL, IS NOT NULL
( ), NOT, AND, OR
*/
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = 'Julia';
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE SALARY >= 9000;
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE MANAGER_ID = '';
SELECT FIRST_NAME, LAST_NAME, MANAGER_ID, SALARY
FROM EMPLOYEES
WHERE MANAGER_ID IS NULL; -- = NULL != ''
SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
WHERE FIRST_NAME = 'Shanta'
OR FIRST_NAME = 'John';
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = 'Shanta'
OR FIRST_NAME = 'John'
AND SALARY > 3000;
-- 날짜 형식
SELECT *
FROM EMPLOYEES
WHERE HIRE_DATE > '07/12/31';
WHERE HIRE_DATE > TO_DATE( '07/12/31','YYYY/MM/DD');
-- ALL(AND), ANY(OR)
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = ALL('Julia', 'John');
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = 'Julia' AND FIRST_NAME = 'John';
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = ANY('Julia', 'John', 'Steven');
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME = 'Julia' OR FIRST_NAME = 'John';
-- IN(OR), NOT IN
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME IN('Julia', 'John');
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE FIRST_NAME NOT IN('Julia', 'John');
-- EXISTS
SELECT FIRST_NAME, LAST_NAME, SALARY
FROM EMPLOYEES
WHERE EXISTS(SELECT 1 FROM DUAL);
SELECT FIRST_NAME, LAST_NAME, SALARY, JOB_ID
FROM EMPLOYEES A
WHERE EXISTS(SELECT 1 FROM DUAL
WHERE A.JOB_ID = 'IT_PROG');
SELECT FIRST_NAME, LAST_NAME, SALARY, JOB_ID
FROM EMPLOYEES
WHERE JOB_ID = 'IT_PROG';
-- BETWEEN 범위 연산자
/*
SALARY >= 3200 AND SALARY <= 9000
BETWEEN 3200 AND 9000
*/
SELECT FIRST_NAME, SALARY
FROM EMPLOYEES
WHERE SALARY BETWEEN 3200 AND 9000;
SELECT FIRST_NAME, SALARY
FROM EMPLOYEES
WHERE SALARY NOT BETWEEN 3200 AND 9000;
-- LIKE
SELECT FIRST_NAME
FROM EMPLOYEES
WHERE FIRST_NAME LIKE 'G_ra_d'; -- _ 한글자
-- % 는 앞뒤 포함시킨다는뜻
SELECT FIRST_NAME
FROM EMPLOYEES
WHERE FIRST_NAME LIKE 'K%y';
SELECT FIRST_NAME, HIRE_DATE
FROM EMPLOYEES
WHERE HIRE_DATE LIKE '06/%';
'Oracle Database > SQL' 카테고리의 다른 글
SQL 쿼리문 기본 (0) | 2018.06.26 |
---|---|
SQL 쿼리 그룹 (0) | 2018.06.26 |
SQL 쿼리 정렬 (0) | 2018.06.26 |
Oracle Database 사용방법 및 주석 (0) | 2018.06.20 |
Oracle Database (SELECT - WHERE)문 (0) | 2018.06.20 |