250x250
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 문서
- Source
- AJAX
- Thymeleaf
- myBatis
- oracle
- JavaScript
- spring
- Tomcat
- Exception
- ubuntu
- maven
- jpa
- MSSQL
- 설정
- SpringBoot
- STS
- Core Java
- git
- Open Source
- Python
- Eclipse
- Spring Boot
- 오픈소스
- PostgreSQL
- IntelliJ
- JDBC
- Docker
- MySQL
- error
Archives
- Today
- Total
헤르메스 LIFE
[Oracle] PL/SQL 예제 본문
728x90
FOR..LOOP
DECLARE
BEGIN
DBMS_OUTPUT.ENABLE;
FOR EMP_LIST IN (
SELECT *
FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'YYYYMMDD') BETWEEN '20000101' AND '20101231'
AND LAST_NAME = 'King'
) LOOP
DBMS_OUTPUT.PUT_LINE('EMPLOYEE_ID :: ' || EMP_LIST.EMPLOYEE_ID);
DBMS_OUTPUT.PUT_LINE('FIRST_NAME :: ' || EMP_LIST.FIRST_NAME);
DBMS_OUTPUT.PUT_LINE('LAST_NAME :: ' || EMP_LIST.LAST_NAME);
DBMS_OUTPUT.PUT_LINE('EMAIL :: ' || EMP_LIST.EMAIL);
DBMS_OUTPUT.PUT_LINE('PHONE_NUMBER :: ' || EMP_LIST.PHONE_NUMBER);
DBMS_OUTPUT.PUT_LINE('HIRE_DATE :: ' || EMP_LIST.HIRE_DATE);
DBMS_OUTPUT.PUT_LINE('JOB_ID :: ' || EMP_LIST.JOB_ID);
DBMS_OUTPUT.PUT_LINE('SALARY :: ' || EMP_LIST.SALARY);
DBMS_OUTPUT.PUT_LINE('COMMISSION_PCT :: ' || EMP_LIST.COMMISSION_PCT);
DBMS_OUTPUT.PUT_LINE('MANAGER_ID :: ' || EMP_LIST.MANAGER_ID);
DBMS_OUTPUT.PUT_LINE('DEPARTMENT_ID :: ' || EMP_LIST.DEPARTMENT_ID);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('SQLCODE :: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM :: ' || SQLERRM);
END;
CURSOR
DECLARE
CURSOR CUR_EMP IS
SELECT *
FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'YYYYMMDD') BETWEEN '20000101' AND '20101231'
AND LAST_NAME = 'King'
;
BEGIN
FOR CUR IN CUR_EMP LOOP
BEGIN
DBMS_OUTPUT.PUT_LINE('EMPLOYEE_ID :: ' || CUR.EMPLOYEE_ID);
DBMS_OUTPUT.PUT_LINE('FIRST_NAME :: ' || CUR.FIRST_NAME);
DBMS_OUTPUT.PUT_LINE('LAST_NAME :: ' || CUR.LAST_NAME);
DBMS_OUTPUT.PUT_LINE('EMAIL :: ' || CUR.EMAIL);
DBMS_OUTPUT.PUT_LINE('PHONE_NUMBER :: ' || CUR.PHONE_NUMBER);
DBMS_OUTPUT.PUT_LINE('HIRE_DATE :: ' || CUR.HIRE_DATE);
DBMS_OUTPUT.PUT_LINE('JOB_ID :: ' || CUR.JOB_ID);
DBMS_OUTPUT.PUT_LINE('SALARY :: ' || CUR.SALARY);
DBMS_OUTPUT.PUT_LINE('COMMISSION_PCT :: ' || CUR.COMMISSION_PCT);
DBMS_OUTPUT.PUT_LINE('MANAGER_ID :: ' || CUR.MANAGER_ID);
DBMS_OUTPUT.PUT_LINE('DEPARTMENT_ID :: ' || CUR.DEPARTMENT_ID);
END;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('SQLCODE :: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM :: ' || SQLERRM);
END;
DECLARE
CURSOR CUR_EMP IS
SELECT *
FROM EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'YYYYMMDD') BETWEEN '20000101' AND '20101231'
AND LAST_NAME = 'King'
;
CUR EMPLOYEES%ROWTYPE;
BEGIN
OPEN CUR_EMP;
LOOP
FETCH CUR_EMP
INTO CUR;
EXIT WHEN CUR_EMP%NOTFOUND;
BEGIN
DBMS_OUTPUT.PUT_LINE('EMPLOYEE_ID :: ' || CUR.EMPLOYEE_ID);
DBMS_OUTPUT.PUT_LINE('FIRST_NAME :: ' || CUR.FIRST_NAME);
DBMS_OUTPUT.PUT_LINE('LAST_NAME :: ' || CUR.LAST_NAME);
DBMS_OUTPUT.PUT_LINE('EMAIL :: ' || CUR.EMAIL);
DBMS_OUTPUT.PUT_LINE('PHONE_NUMBER :: ' || CUR.PHONE_NUMBER);
DBMS_OUTPUT.PUT_LINE('HIRE_DATE :: ' || CUR.HIRE_DATE);
DBMS_OUTPUT.PUT_LINE('JOB_ID :: ' || CUR.JOB_ID);
DBMS_OUTPUT.PUT_LINE('SALARY :: ' || CUR.SALARY);
DBMS_OUTPUT.PUT_LINE('COMMISSION_PCT :: ' || CUR.COMMISSION_PCT);
DBMS_OUTPUT.PUT_LINE('MANAGER_ID :: ' || CUR.MANAGER_ID);
DBMS_OUTPUT.PUT_LINE('DEPARTMENT_ID :: ' || CUR.DEPARTMENT_ID);
END;
END LOOP;
CLOSE CUR_EMP;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('SQLCODE :: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM :: ' || SQLERRM);
END;
https://hermeslog.tistory.com/287
https://hermeslog.tistory.com/289
https://hermeslog.tistory.com/291
728x90
'Database' 카테고리의 다른 글
[Oracle] Pipelined Table Functions (0) | 2015.10.08 |
---|---|
[Oracle] TRUNC, ROUND 차이 (0) | 2015.10.02 |
[Oracle] LAG, LEAD - 이전, 이후 비교함수, 합계 (0) | 2015.10.02 |
[Oracle] PL/SQL PREDEFINED EXCEPTION - 미리정의된 예약 (0) | 2015.09.30 |
[Oracle] PL/SQL 예외처리 (0) | 2015.09.30 |