pl/sql 기본구조
declare
선언
begin
실행
exception
예외처리
end;
선언부
변수명 타입;
OR
변수명 테이블명.컬럼명%TYPE;
이라고 하면 자동으로 해당 컬럼명의 타입으로 선언
실행부
if문
if 조건 then
처리
elsif 조건 then
처리
else
처리
end if;
case 문
case 값
when 값 then
처리
when 값 then
처리
else
처리
end case;
반복문
loop
처리문장
(종료를 위한 exit; 구분이 있어야함)
(exit when 조건;)
end loop;
while 조건 loop
처리부
end loop;
for 카운터 in (reverse) 최소..최대 loop
처리문장
(카운터는 자동으로 1씩 증가 혹은 감소)
end loop;
라벨 쓰는법
<<라벨 이름>> (라벨 선언)
GOTO 라벨이름;
"GOTO 라벨명"을 만나면 라벨을 선언한 위치로 이동
예외처리부
exception when 예외1 then
처리1
when 예외2 then
처리2
when others then
처리
함수
create or replace function 함수명 (인자1 타입, 인자2 타입)
return 데이터타입 is [AS]
변수선언;
begin
처리내용
return 리턴값;
end;
함수 삭제
drop function 함수명;
프로시저
create or replace procedure 프로시저이름
in 인자
out 인자
in out 인자
is
변수 선언
begin
실행문
end;
프로시저 삭제
drop procedure 프로시저명;
'공부 > oracle' 카테고리의 다른 글
oracle auto_increment 구현 (sequence) (0) | 2012.11.23 |
---|---|
oracle limit 기능 구현 (0) | 2012.11.23 |
oracle 사용자 권한 설정 (0) | 2012.11.23 |