용어
1. 용어, DML
1. 용어 1.1. 테이블 명명 테이블명과 컬럼명은 반드시 문자로 시작, 최대 30자 영문자, 숫자, 특수기호(_ , $ , #)만으로 구성 동일 사용자가 생성한 다른 객체의 이름과 중복되면 안된다. 예약어 사
code-is-me.tistory.com
- 용어
- varchar2
- char
- number
- date
- long
- raw
- longraw
where
3. where, 연산자
주의 where title != null; -- 에러 where title is not null; -- 정상 작동 1. where where 에 들어가는 것 형식 값 연산자 subquery - subqueary 블로그에서 설명 where : 해당 조건일 때만 적용되는 문법 SELECT * FROM STUDENT.S
code-is-me.tistory.com
- 형식
- 값
- 연산자
- subquery
연산자
3. where, 연산자
주의 where title != null; -- 에러 where title is not null; -- 정상 작동 1. where where 에 들어가는 것 형식 값 연산자 subquery - subqueary 블로그에서 설명 where : 해당 조건일 때만 적용되는 문법 SELECT * FROM STUDENT.S
code-is-me.tistory.com
- 논리
- AND
- OR
- 논리 비교
- != = < > <= >= <>
- != = < > <= >= <>
- sql 비교
- between and
- in
- is null
- like
- _
- %
- multi row 연산자 - 고급 sql
- in | not in
- any
- all
- exists | not exists
단일행 함수, 다중행 함수
4. 단일행 함수, 다중행 함수
함수 사용 위치 : select 컬럼명, having, order by , where 연산자 조건 등등 대체로 다 사용됨. - 논리적으로 사용하기 단일 행 함수 문자형 upper, lower, initcap concat, substr length, lpad, rpad ltrim, rtrim replace, tran
code-is-me.tistory.com
사용 위치 : select 컬럼명, having, order by , where 연산자 조건 등등 대체로 다 사용됨. - 논리적으로 사용하기
- 단일 행 함수
- 문자형
- upper, lower, initcap
- concat, substr
- length, lpad, rpad
- ltrim, rtrim
- replace, translate
- 숫자형
- round(반올림), trunc(내림), mod(나머지)
- power(제곱), sqrt(루트), sign(양,음,0), chr(인코딩)
- 날짜형
- sysdate, last_day
- months_between, add_months
- round, trunc
- 변환형
- To_Number
- To_char
- 요소: 9, 0, $, ㅣ, . , ,
- To_Date
- 요소: YYYY, MM , etc
- 요소: YYYY, MM , etc
- 문자형
- 다중 행 함수
- 그룹함수
- Count(*) - null 포함
- Count(), avg(), sum(), min(), max() stddev(), variance() - null 포함 안함
- 그룹함수
SQL 명령어
- Select 기본
- select from where order by
- select from where group by having order by
- DML
- Insert
- insert into values
- Update
- update set where
- delete
- delete from where
- delete from where
- Insert
- DDL
- create
- alter
- drop
- rename
- truncate
- comment
- transaction Control (tx)
- commit
- rollback
- savepoint
- DCL
- grant
- revoke
- role
select에 자주 사용되는 개념
- subGroup
- group by
- having
- join
== 이중 for 문
사용 위치 : whrere절
- equijoin
- non-equijoin : 등급
- outer join : (+), data가 부족한 쪽
- self join : 계층구조, alias 필요
- set
- select 구문 들끼리 연결
- 개수와 타입이 일치 필요
- 종류
- union 합
- union all 중복 포함 합
- intersect 교집합
- minus 차집합
- subQuery
- 순서 : sub query(1) -> main query(2)
- 종류
- single row : 1개
- multi row : 한 종류 column type 해당 값 여러개
- multi 연산자 : in, not in, any, exists, not exists - 고급 sql
- multi column : 여러종류 colum type 해당 값 한개
- single row : 1개
- 위치
- from절
- having절
- select 절 상관쿼리
- create 절
- insert 절
- update 절
- 순서 : sub query(1) -> main query(2)
meta 정보
- constraint = 제약 조건
- 적용 범위
- column level
- table level: not null 빼고 다
- 종류
- pk : not null + unique
- fk : on delete cascade
- not null
- unique
- check: 반드시 참이여야 하는 조건
- 무결성 제약 조건
- 상식적으로 pk와 fk의 연관성 생각하기
- 상식적으로 pk와 fk의 연관성 생각하기
- 적용 범위
- transaction Control (tx) - 마리오 게임
- 명령어
- commit : 저장
- savepoint : rollback 할 위치 - 임시저장
- rollback : 저장 전으로 돌아감
- implicit 제어 명령어
- 자동 commit : ddl, dcl
- rollback : 비정상 종료
- 명령어
- dictionary
- read only - view, table 집합
- dictionary view 종류
- user
- all
- dba
- v$
- ind
- dictionary
- table privileges
- read only - view, table 집합
DDL , DCL
- DDL
- create
- drop: 기존 table 싹 날림
- alter
- column 추가
- 컬럼 수정
- 제약조건 추가
- 제약조건 삭제
- truncate : 기존 table 틀만 남기고 싹 날림
- rename
- comment : table에 주석 문장 - 제일 중요 실무
- create
- DCL
- Privilege
- role: privilege의 그룹 - 인터페이스 같은 것
- 생성
- grant, revoke로 권한 지정
- grant
- revoke
Object
14. Object
object 종류 table, sequence, index, view, synonym, progrem unit sequence : nextval, currval 생성 insert문에서 column명에 사용 변경, 삭제 가능 index column 생성시 자동으로 rowId로 생성 user가 index 생성시, 논리적, 물리적
code-is-me.tistory.com
- 종류
- table, sequence, index, view, synonym, progrem unit
- sequence : nextval, currval
- 생성
- insert문에서 column명에 사용
- 변경, 삭제 가능
- index
- column 생성시 자동으로 rowId로 생성
- user가 index 생성시,
- 논리적, 물리적 독립적 테이블
- rowId, index column 값을 가진다.
- 해당 조건을 검색시 b-tree를 통해서 빠르게 탐색
- 사용 조건
- where, join 많이 쓸 때
- 기본 data 값이 많고 찾는 데이터가 10~15%
- column 생성시 자동으로 rowId로 생성
- view
- method()
- orderby 사용 못함
- dml 수행 못함
- 객체, 실제 값 존재 안함
- 자주 쓰이는 join table을 쉽게 사용할 때
- 생성 방법
- 사용 방법
- syonym
- 별명
- table, sequence, index, view, synonym, progrem unit
고급 sql
- nvl
- decode == case
- pivot : 보기 좋게 table 형태
- rollup
- cube
- rank
- correlated subquery : main queary(1) -> sub queary (2) * main queary에 별명 꼭 필요
- multi 연산자 : in, not in, any, exists, not exists
- pseudo column : rowid, rownum(무조건 1부터)
- index 효율적 사용
- trigger 자동 실행 프로그램