SET SERVEROUTPUT ON;
DECLARE
VN_SALARY NUMBER := 0;
VN_DEPARTMENT_ID NUMBER := 0;
BEGIN
VN_DEPARTMENT_ID := ROUND(DBMS_RANDOM.VALUE(10, 120), -1);
SELECT SALARY
INTO VN_SALARY
FROM EMPLOYEES
WHERE DEPARTMENT_ID = VN_DEPARTMENT_ID
AND ROWNUM = 1;
DBMS_OUTPUT.PUT_LINE(VN_SALARY);
-- IF VN_SALARY BETWEEN 1 AND 3000 THEN
-- DBMS_OUTPUT.PUT_LINE('낮음');
-- ELSIF VN_SALARY BETWEEN 3001 AND 6000 THEN
-- DBMS_OUTPUT.PUT_LINE('중간');
-- ELSIF VN_SALARY BETWEEN 6001 AND 10000 THEN
-- DBMS_OUTPUT.PUT_LINE('높음');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('최상위');
-- END IF;
-- 위의 다중IF문 -> CASE문으로 변경
CASE
WHEN VN_SALARY BETWEEN 1 AND 3000 THEN
DBMS_OUTPUT.PUT_LINE('낮음');
WHEN VN_SALARY BETWEEN 3001 AND 6000 THEN
DBMS_OUTPUT.PUT_LINE('중간');
WHEN VN_SALARY BETWEEN 6001 AND 10000 THEN
DBMS_OUTPUT.PUT_LINE('높음');
ELSE
DBMS_OUTPUT.PUT_LINE('최상위');
END CASE;
END;
댓글남기기