오라클 공식 사이트 - tool이나 manual 등
(otn.oracle.com/kr)
* tools - instant client, sql developer (둘다 기업에서 사용해도 무료임)
* manual
PL/SQL <- Ada <- Pascal
- 블럭형 구조
declare
v_sal1 number;
v_sal2 number;
begin
select sal into v_sal1
from emp
where empno = '7788';
-- 주석
/* 주석 */
select sal into v_sal2
from emp
where empno = '7782';
if v_sal1 > v_sal2 then
dbms_output.put_line('7788win');
end if;
end;
/
; - 전체 블럭의 종료
/ - 실행
변수 선언시 참고할 점
변수의 데이터형을 정할때, db의 자료형이 변하는경우를 생각하여 그때 끄때 db의 자료형에 맞춰갈 수 있도록 선언하는 방법
declare
v_ename emp.ename%type; -- 변수 하나
v_job emp.job%type;
emp_rec emp%rowtype; -- 하나의 레코드
TYPE emp_record_type IS RECORD -- data type 생성
(ename emp.ename%type,
job emp.job%type,
sal emp.sal%type);
emp_rec1 emp_record_type; -- data type instance 생성
emp_rec2 emp_record_type; -- data type instance 생성
TYPE emp_sal_table_type IS TABLE OF emp.sal%type
INDEX BY PLS_INTEGER; -- 배열 타입 생성
emp_sal_tab1 emp_sal_table_type; -- 배열 instance 생성
emp_sal_tab2 emp_sal_table_type;
TYPE emp_tab_row_type IS TABLE OF emp%rowtype
INDEX BY PLS_INTEGER; -- 구조체 배열 타입 생성
emp_tab_row emp_tab_row_type; -- 구조체 배열 instance생성
begin
select ename, job, sal into emp_rec1
from emp
where empno = 7788;
select * into emp_rec
from emp
where empno = 7782;
dbms_output.put_line(emp_rec.ename||' '||to_char(emp_rec.sal));
select sal bulk collect into emp_sal_tab1
from emp
where deptno = 10;
select * bulk collect into emp_tab_row
from emp
where deptno = 10;
end;
/
## 모든 에러는 번호로 알 수 있지만, 모든 예외처리는 이름으로 한다
1. Predefined
2. Non-predefined -> when others then
3. Non-predefined -> 이름 붙여서
4. User-defined
5. User-defined
===================================================================================
바탕 화면.zip
comment