본문 바로가기
Oracle

Oracle (1) - 개념 정리

by leehii 2022. 5. 31.

database 개론

-- hr 계정에서 사용 할 수 있는 테이블 조회
select table_name from user_tables; 

--  테이블 속성 조회 

desc department 
desc employees

desc TITLE


-- 컬럼 길이의 조정

select first_name, last_name
from employees;

column last_name format a18
column department_name format a18

column last_name format a18
column first_name format a18

column last_name format a18 

select first_name, last_name
from employees


-- SQLplus 환경설정
column last_name format a18
column department_name format a18
show linesize 
set linesize 100

show pagesize
set pagesize 40

show user 

cl scr > 스크린 지우는것 


------직원의 조회 

-- 셀렉션 
select * from employees

SELECT * FROM TITLE_COPY

SELECT * FROM TITLE_id

SELECT * FROM RESERVATION

SELECT * FROM rental
SELTITLE_ID

-- 프로젝션

select employee_id, last_name, job_id
from employees;

select employee_id, last_name, job_id
from employees;

-- 계정을 바꿀 때 conn
conn scott/tiger 

--- 아예 종료되는 명렁어 
exit quit

표준 sql : sql - 1999 이 기준에 맞춰서 변형이 생김 
    테이블명을 따라간다고함 


-- DQL : selext 질의어 질문하는 데이터 베이스에 질문하는 언어
-- DML : insert, update, delete 데이터베이스 조절 
-- DDL : create, drop, alter 데이터베이스 정의 
-- TCL : commit, rollbcak 데이터베이스 삭제
-- DCL : grant
-- 문법 규격이있음

-- Oracle의 객체 종류
  --, 테이블, 인덱스, 뷰, 시퀀스 (은행가면 표 뽑느것 처럼), 시노님(테이블에 대한별명),
  -- 프로시져 (프로그램), 함수, 패키지, 트리거 (어떤 사건들 DML 작업 사건 발생 이후 작업 연쇄적으로)
  -- EX) 은행에서 돈 뽑고 그 이후 정리하는 작업 / 신용, 돈 잔액, 언제 뽑았는지 등등 
  --) 데이터 수정 후 이후 진행 되는   

---테이블 join
select *
from table_name 테이블명 (data set) 데이터의 집합 


--------select


-- 셀렉션 
select * from employees


SELECT * FROM MEMBER;
--* 테이블 전체

-- 프로젝션

select employee_id, last_name, job_id
from employees;

select 절
 -. * 
 -. DISTINCT : 중복값을 제외한다. 
 -. column : from절에 기술 된 테이블의 항목 (컬럼)
 -. alias : 별명 
    column 문자열 > department_id did
column as 별명 > department_id as did
    column "did"  > department_id as did
column as "별명" > department_id as "did"
(column) 별명 > (department_id) as "did" - 여러 기호를 쓸 때 이렇게 소문자를 씀

 -. 연산 가능 : +,-,*,/
 -. || > 문자열 연결 
 -. 함수 


from 절 table, table, ....

 table명, dataset (테이블,쿼리)
 
where 절  : 조건절 
  조건식 : a = b  연산식이 되어야함 
  조건식이 여러개 연결 될 때는 and, or 연결한다. 
  문자열, 날짜의 값을 비교 홑따옴표 ('')를 사용한다. 
  값을 비교시 대소문자를 구별한다. 
  우선순위 
  산술 연산자가 > 연결 연산자 (||) > 비교조건 > is null, in > between
  and(범위) : between 5000 and 10000
  or       : in (a,b,c) 
  like    : 비슷한 자료를 조회 ex> ~%
       % : 모든 값 길이에 무관 포함 조회
    _ : 문자 한글자만 조회
      null : is null, is not null
  
  group by
  having
  
  order by : 정렬
 - column : select절에 column, 별명도 쓸 수 있음 
   asc : 오름차순, desc : 내림차순