SQL>
SQL> CREATE TABLE lecturer (
2 id NUMBER(5) PRIMARY KEY,
3 first_name VARCHAR2(20),
4 last_name VARCHAR2(20),
5 major VARCHAR2(30),
6 current_credits NUMBER(3)
7 );
Table created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10001, 'Scott', 'Lawson','Computer Science', 11);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major, current_credits)
2 VALUES (10002, 'Mar', 'Wells','History', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10003, 'Jone', 'Bliss','Computer Science', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10004, 'Man', 'Kyte','Economics', 8);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10005, 'Pat', 'Poll','History', 4);
1 row created.
SQL>
SQL> INSERT INTO lecturer (id, first_name, last_name, major,current_credits)
2 VALUES (10006, 'Tim', 'Viper','History', 4);
1 row created.
SQL>
SQL>
SQL> CREATE OR REPLACE PROCEDURE DeleteMajor(
2 p_Major IN lecturer.major%TYPE,
3 p_RowsDeleted OUT INTEGER) AS
4
5 v_CursorID INTEGER;
6 v_DeleteStmt VARCHAR2(100);
7 BEGIN
8 v_CursorID := DBMS_SQL.OPEN_CURSOR;
9
10 v_DeleteStmt := 'DELETE FROM lecturer WHERE major = :m';
11
12 DBMS_SQL.PARSE(v_CursorID, v_DeleteStmt, DBMS_SQL.V7);
13
14 DBMS_SQL.BIND_VARIABLE(v_CursorID, ':m', p_Major);
15
16 p_RowsDeleted := DBMS_SQL.EXECUTE(v_CursorID);
17
18 DBMS_SQL.CLOSE_CURSOR(v_CursorID);
19 EXCEPTION
20 WHEN OTHERS THEN
21 DBMS_SQL.CLOSE_CURSOR(v_CursorID);
22 RAISE;
23 END DeleteMajor;
24 /
Procedure created.
SQL>
SQL> drop table lecturer;
Table dropped.
SQL>