Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- golang
- 알고리즘
- 쿼리
- 자료구조
- 운영체제
- Spring Boot
- Kafka
- Spring Cloud Feign
- 오라클
- SQL
- 클라우드
- 페이징
- Spring
- 데이터베이스
- Jenkins
- Spring Cloud
- retry
- db
- PL/SQL
- Intellj
- 코딩
- MVC
- feign
- aws
- 자바
- JPA
- MST
- 백준
- DP
- 디자인 패턴
Archives
- Today
- Total
justgo_developer
조건문(if문, case문) 본문
728x90
반응형
제어문 : 조건문, 반복문
- 조건문 : if문, case문
- 반복문 : basic loop문, while문(반복횟수를 정하지 않을 경우)
for문(반복횟수를 지정할 경우)
//if문 : if~end if문
if(조건) then
실행명령;
end if;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | declare emp_id employees.employee_id%type; emp_name employees.last_name%type; emp_dept employees.department_id%type; dept_name varchar2(20) := null; begin select employee_id, last_name, department_id into emp_id, emp_name, emp_dept from employees where employee_id = 124; if(emp_dept = 50) then --if문 시작 dept_name := 'Shipping'; end if; if(emp_dept = 60) then dept_name := 'IT'; end if; if(emp_dept = 70) then dept_name := 'Public Relation'; end if; if(emp_dept = 80) then dept_name := 'Sales'; end if; dbms_output.put_line(emp_id || ' ' || emp_name || ' ' || emp_dept || ' ' || dept_name); end; | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | declare emp_id employees.employee_id%type; emp_name employees.last_name%type; emp_dept employees.department_id%type; dept_name varchar2(20) := null; begin select employee_id, last_name, department_id into emp_id, emp_name, emp_dept from employees where employee_id = 124; if(emp_dept = 50) then dept_name := 'Shipping'; elsif(emp_dept = 60) then dept_name := 'IT'; elsif(emp_dept = 70) then dept_name := 'Public Relation'; elsif(emp_dept = 80) then dept_name := 'Sales'; end if; dbms_output.put_line(emp_id || ' ' || emp_name || ' ' || emp_dept || ' ' || dept_name); end; | cs |
※ PL/SQL에서는 else if -> elsif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | declare emp_id employee.employee_id%type; emp_name employee.last_name%type; emp_comm employee.commission_pct%type := null; begin select employee_id, last_name, commission_pct into emp_id, emp_name, emp_comm from employee where employee_id = 130; if(emp_comm > 0) then dbms_output.put_line(emp_id || '의 보너스는 ' || emp_comm ||'입니다.'); else dbms_output.put_line('보너스가 없다'); end if; end; | cs |
case문
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | declare emp_id employees.employee_id%type; emp_name employees.last_name%type; emp_dept employees.department_id%type; dept_name varchar2(20) := null; begin select employee_id, last_name, department_id into emp_id, emp_name, emp_dept from employees where employee_id = &empno; dept_name := case emp_dept when 50 then 'Shipping' when 60 then 'IT' when 70 then 'Public Relation' when 80 then 'Sales' end; dbms_output.put_line(emp_dept); end; | cs |
728x90
반응형
'IT > Oracle' 카테고리의 다른 글
커서의 의미와 사용예 (0) | 2018.12.09 |
---|---|
반복문(basic loop, while, for loop, continue) (0) | 2018.12.08 |
콜렉션, 바인드 변수 (0) | 2018.12.02 |
rowType 변수 및 복합변수 활용 (0) | 2018.12.01 |
PL/SQL (0) | 2018.11.30 |