Index | Home | Forums
Oracle PL/SQL Example 2-14 Using a Block Label for Name Resolution

Example 2-14 Using a Block Label for Name Resolution

CREATE TABLE employees2 AS SELECT last_name FROM employees;
<<main>>
DECLARE
   last_name VARCHAR2(10) := 'King';
   v_last_name VARCHAR2(10) := 'King';
BEGIN
-- deletes everyone, because both LAST_NAMEs refer to the column
   DELETE FROM employees2 WHERE last_name = last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
-- OK, column and variable have different names
   DELETE FROM employees2 WHERE last_name = v_last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
-- OK, block name specifies that 2nd last_name is a variable
   DELETE FROM employees2 WHERE last_name = main.last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
END;
/


This page was generated on/at Feb 23,2008 00:20:12
General comments and questions regarding this document should be sent by email to info@oracleabc.com or post your comments here




Index | Home | Forums
Oracle PL/SQL Example 2-14 Using a Block Label for Name Resolution

Example 2-14 Using a Block Label for Name Resolution

CREATE TABLE employees2 AS SELECT last_name FROM employees;
<<main>>
DECLARE
   last_name VARCHAR2(10) := 'King';
   v_last_name VARCHAR2(10) := 'King';
BEGIN
-- deletes everyone, because both LAST_NAMEs refer to the column
   DELETE FROM employees2 WHERE last_name = last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
-- OK, column and variable have different names
   DELETE FROM employees2 WHERE last_name = v_last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
-- OK, block name specifies that 2nd last_name is a variable
   DELETE FROM employees2 WHERE last_name = main.last_name;
   DBMS_OUTPUT.PUT_LINE('Deleted ' || SQL%ROWCOUNT || ' rows.');
   ROLLBACK;
END;
/


This page was created by oracleabc.com on Feb 23,2008 00:09:02
General comments and questions regarding this document should be sent by email to info@oracleabc.com or post your comments here