Lab 2. Introduction To PL/SQL and Cursors
Lab 2. Introduction To PL/SQL and Cursors
Lab 2. Introduction To PL/SQL and Cursors
DECLARE
V_Sample1 NUMBER(2);
V_Sample2 CONSTANT NUMBER(2):=10;
V_Sample3 NUMBER(2) NOT NULL:=1 ;
V_Sample4 NUMBER(2) := 50;
V_Sample5 NUMBER(2) DEFAULT 25;
7 begin
8 dbms_output.put_line('proceed');
9 END;
10 /
2-
DECLARE --outer block
2 var_num1 NUMBER := 5;
3 BEGIN
4 DECLARE --inner block
5 var_num1 NUMBER := 10;
6 BEGIN
7 DBMS_OUTPUT.PUT_LINE('Value for var_num1:' ||var_num1);
8 DBMS_OUTPUT.PUT_LINE('Value for outer block var_num1:' ||var_num1);
9 end;
10 end;
11 /
2.3. Write a PL/SQL block to retrieve all staff (code, name, salary)
under specific department number and display the result. (Note: The
Department_Code will be accepted from user. Cursor to be used.)
DECLARE
C_REV STAFF_MASTERS%ROWTYPE;
BEGIN
OPEN C_STAFF_MASTERS;
LOOP
END LOOP;
CLOSE C_STAFF_MASTERS;
END;
C1_SAL NUMBER(10);
C2_SAL NUMBER(10);
C_SAL STAFF_MASTERS.STAFF_SAL%TYPE;
BEGIN
OPEN C_STAFF_MASTERS;
LOOP
C1_SAL:=C_SAL*0.3;
C2_SAL:=C_SAL+5000;
IF C1_SAL>C2_SAL THEN
ELSE
END IF;
DBMS_OUTPUT.PUT_LINE(C_SAL);
END LOOP;
CLOSE C_STAFF_MASTERS;
END;
OR WITHOUT CURSOR-
SQL> DECLARE
2 V_SAL STAFF_MASTERS.STAFF_SAL%TYPE;
3 V_DEPT STAFF_MASTERS.DEPT_CODE%TYPE;
4 BEGIN
5 SELECT MIN(STAFF_SAL) INTO V_SAL FROM STAFF_MASTERS WHERE
DEPT_CODE=&V_DEPT;
6 DBMS_OUTPUT.PUT_LINE('SALARY AFTER INCREMENT: '||V_SAL);
7 END;
8 /