SQL> CREATE TABLE emp (
2 id NUMBER PRIMARY KEY,
3 fname VARCHAR2(50),
4 lname VARCHAR2(50)
5 );
Table created.
SQL>
SQL> INSERT INTO emp (id, fname, lname)VALUES (1, 'A', 'B');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (2, 'C', 'D');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (3, 'Enn', 'F');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (4, 'G', 'H');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (5, 'G', 'Z');
1 row created.
SQL>
SQL>
SQL> DECLARE
2 v_emp emp%ROWTYPE;
3 BEGIN
4 SELECT * INTO v_emp FROM emp WHERE id = 54;
5
6 DELETE FROM emp WHERE id = v_emp.id;
7
8 DBMS_OUTPUT.PUT_LINE('emp '||v_emp.fname||' '||v_emp.lname||' has been deleted');
9
10 COMMIT;
11
12 EXCEPTION
13 WHEN OTHERS
14 THEN
15 DBMS_OUTPUT.PUT_LINE(SQLERRM);
16 ROLLBACK;
17 END;
18 /
ORA-01403: no data found
PL/SQL procedure successfully completed.
SQL>
SQL> set escape off
SQL>
SQL>
SQL> drop table emp;
Table dropped.
|