************** ºÎ¼/Á÷¿ø ¸®Æ÷Æ® ******************
ºÎ¼ : ºÎ¼¹øÈ£ ºÎ¼¸í
À§Ä¡
10 ACCOUNTING NEW YORK
»ç¿ø : »ç¹ø À̸§ ±Þ¿©
±Þ¿© µî±Þ
7871
Anderson 2000 ***
7890 Andrew 700
*
7870 Scott 2400 ****
7866
David 900 *
7891 Sylvia 3200
*****
2¸íÀÇ ±Þ¿©°¡ ÀλóµÇ¾ú½À´Ï´Ù.
À§¿Í °°Àº ¸®Æ÷Æ®¸¦
»Ì¾Æ³»°í $1000º¸´Ù ÀûÀº ±Þ¿©¸¦ ¹Þ´Â Á÷¿øÀÇ ±Þ¿©¸¦ 10%ÀλóÇÏ´Â ÇÁ·Î±×·¥À» ÀÛ¼ºÇÏ¿© º¾´Ï´Ù.
ACCEPT p_deptno PROMPT 'Please enter the department number : '
DECLARE
v_deptno
NUMBER(2);
v_dname CHAR(14);
v_loc
CHAR(13);
v_empno emp.empno%TYPE;
v_ename
emp.ename%TYPE;
v_sal emp.sal%TYPE;
v_grade
salgrade.grade%TYPE;
v_dno emp.deptno%TYPE :=
&p_deptno;
CURSOR emp_cursor IS
SELECLT empno,
ename, sal
FROM emp
WHERE deptno =
&p_deptno;
e_no_emp EXCEPTION;
BEGIN
-- print out the
report title
DBMS_OUTPUT.PUT_LINE('*********ºÎ¼/Á÷¿ø
¸®Æ÷Æ®*********');
SELECT deptno, dname, loc
INTO v_deptno,
v_dname, v_loc
FROM dept
WHERE deptno =
v_dno;
DBMS_OUTPUT.PUT_LINE('ºÎ¼ : ºÎ¼¹øÈ£ ºÎ¼¸í
À§Ä¡');
DBMS_OUTPUT.PUT_LINE(' '¡«v_deptno¡«'
'¡«v_dname¡«
' '¡«v_loc¡«'
');
DBMS_OUTPUT.PUT_LINE('»ç¿ø : »ç¹ø À̸§ ±Þ¿©
±Þ¿©µî±Þ');
OPEN emp_cursor;
FETCH emp_cursor INTO v_empno,
v_ename, v_sal;
/* according to the salary amount,
print
out the stars */
WHILE emp_cursor%FOUND LOOP
SELECT
grade
INTO v_grade
FROM
salgrade
WHERE v_sal > losal AND v_sal
<hisal;
DBMS_OUTPUT.PUT(' '¡«v_empno¡«'
'¡«v_ename¡«
' '¡«v_sal¡«' ');
FOR
I in 1..v_grade LOOP
DBMS_OUTPUT.PUT('*');
END
LOOP;
DBMS_OUTPUT.PUT_LINE('');
FETCH emp_cursor INTO
v_empno, v_ename, v_sal;
END LOOP;
CLOSE
emp_cursor;
UPDATE emp
SET sal = sal *
1.1
WHERE sal < 1000;
IF SQL%ROWCOUNT = 0
THEN
RAISE
e_no_emp;
ELSE
DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT ¡«'¸íÀÇ ±Þ¿©°¡
' ||
'ÀλóµÇ¾ú½À´Ï´Ù.');
END
IF;
COMMIT;
EXCEPTION
WHEN no_data_found
THEN
DBMS_OUTPUT.PUT_LINE('There is no matching
data.');
WHEN too_many_rows
THEN
DBMS_OUTPUT.PUT_LINE('More than one matching data.
');
WHEN e_no_emp THEN
DBMS_OUTPUT.PUT_LINE('No employee
with a smaller ' ||
'than
$1000.');
--in case of any other exception
WHEN others
THEN
DBMS_OUTPUT.PUT_LINE('Some other error
occurred.');
END;
|
½Ç½À
1. ¾Æ·¡ ¼±¾ð¹® °¢°¢À» Æò°¡ÇÕ´Ï´Ù. À̰͵é Áß ¾î¶² °ÍÀÌ ¿Ã¹Ù¸£Áö
¾ÊÀ¸¸ç ¿Ö ±×·±°¡¸¦ ¼³¸íÇϽʽÿÀ.
a. |
DECLARE |
______________________________________________________________________
b. |
DECLARE |
______________________________________________________________________
c. |
DECLARE |
º¯¼ö °ª ÁöÁ¤
º¯¼ö °ªÀ» ÁöÁ¤Çϰųª ÀçÁöÁ¤Çϱâ À§ÇØ,
PL/SQL ÁöÁ¤ ¹®ÀåÀ» ¾¹´Ï´Ù. ÁöÁ¤(assignment) ¿¬»êÀÚ (:=)ÀÇ ÁÂÃø¿¡ »õ °ªÀ» ¹Þ±â À§ÇÑ º¯¼ö¸¦ Àû½À´Ï´Ù.
±¸¹®¿¡¼,
identifier ½ºÄ®¶ó º¯¼öÀÇ
À̸§ÀÔ´Ï´Ù.
expr º¯¼ö, ¸®ÅÍ·², ÇÔ¼ö È£ÃâÀÌ µÉ ¼ö ÀÖÁö¸¸ µ¥ÀÌÅͺ£À̽º ¿Àº
¾ÈµË´Ï´Ù.
ÁöÁ¤ º¯¼ö °ª ¿¹´Â ¾Æ·¡¿Í °°ÀÌ Á¤Àǵ˴ϴÙ:
º¯¼ö °ªÀ» ÁöÁ¤Çϱâ À§ÇÑ ´Ù¸¥ ¹æ¹ýÀº µ¥ÀÌÅͺ£À̽º °ª¿¡¼ ÀÎÃâÇϰųª ¼±ÅÃÇÏ´Â °ÍÀÔ´Ï´Ù. ¾Æ·¡ ¿¹¿¡¼, Á¾¾÷¿øÀÇ ±Þ¿©¸¦ ¼±ÅÃÇÒ ¶§ 10% º¸³Ê½º¸¦ °è»êÇϵµ·Ï ÇÕ´Ï´Ù.
SQL> SELECT sal *
0.10 |
À̶§ ´Ù¸¥ °è»ê¿¡¼ º¯¼ö bonus¸¦ »ç¿ëÇÒ ¼ö Àְųª ±× °ªÀ»
µ¥ÀÌÅͺ£À̽º Å×ÀÌºí¿¡ »ðÀÔÇÒ ¼ö ÀÖ½À´Ï´Ù.
ÁÖ: µ¥ÀÌÅͺ£À̽º¿¡¼ÀÇ °ªÀ» º¯¼ö·Î ÁöÁ¤Çϱâ À§ÇØ, SELECT ³ª
FETCH ¹®ÀåÀ» »ç¿ëÇÕ´Ï´Ù.
º¯¼ö´Â ºí·ÏÀ̳ª ¼ºêÇÁ·Î±×·¥ ¾ÈÀ¸·Î µé¾î°¥ ¶§¸¶´Ù Ãʱâȵ˴ϴÙ. µðÆúÆ®·Î º¯¼ö´Â
NULL·Î Ãʱâȵ˴ϴÙ. ¸íÈ®ÇÏ°Ô º¯¼ö¸¦ ÃʱâÈÇÏÁö ¾ÊÀ¸¸é, °ªÀº Á¤ÀǵÇÁö ¾Ê½À´Ï´Ù.
- ƯÁ¤ °ªÀÌ ¾ø´Â º¯¼ö¿¡ ´ëÇØ ÁöÁ¤
¿¬»êÀÚ(:=)¸¦ »ç¿ëÇÕ´Ï´Ù. v_hiredate := to_date('15-SEP-99',
'DD-MON-YY');
|
|
½Ç½À(°è¼Ó)
2. °¢ ¾Æ·¡ ÁöÁ¤¿¡¼ °á°ú Ç¥Çö½ÄÀÇ µ¥ÀÌÅÍ ÇüÀ»
°áÁ¤ÇÕ´Ï´Ù.
a. |
v_days_to_go := v_due_date - SYSDATE; |
______________________________________________________________________
b. |
v_sender := USER || ': ' || TO_CHAR(v_dept_no); |
______________________________________________________________________
c. |
v_sum := $100,000 + $250,000; |
______________________________________________________________________
d. |
v_flag := TRUE; |
______________________________________________________________________
e. |
v_n1 := v_n2 > (2 * v_n3); |
______________________________________________________________________
f. |
v_value := NULL; |
%TYPE ¼Ó¼º°ú º¯¼ö¼±¾ð
|
|
º¯¼ö ÁöÁ¤°ª
È£½ºÆ® º¯¼ö¸¦
ÂüÁ¶Çϱâ À§ÇØ, ¼±¾ðµÈ PL/SQL º¯¼ö¿Í È£½ºÆ® º¯¼ö¸¦ ±¸º°Çϱâ À§ÇØ ÄÝ·Ð(:)À¸·Î ÂüÁ¶ Á¢µÎ¾î¸¦ ¸¸µé¾î¾ß
ÇÕ´Ï´Ù.
¿¹
:host_var1 := v_sal; |
¿¹
SQL>
VARIABLE return_code NUMBER |
´ÙÀ½ Áß ¿Ã¹Ù¸¥ PL/SQL ¹®ÀåÀÌ ¾Æ´Ñ °ÍÀº?
A. v_ename := LOWER(v_ename);
B. v_total
:= SUM(number_total);
C. v_comment := USER||': '||TO_CHAR(SYSDATE);
D.
v_equal := (v_empno IS NOT NULL);
´ä