Friday, November 23, 2012

PL/SQL tips: use %TYPE



Use tablename.columnname%TYPE in your plsql, so when the table column type is changed you don't have to change the types in plsql.


Example (Oracle PL/SQL):

DECLARE

  CURSOR cursorsalary IS SELECT employee_name,salary FROM employees WHERE salary>100;
  name employees.employee_name%TYPE;
  sal employees.salary%TYPE;

BEGIN

 OPEN cursorsalary;

 FOR arow IN cursorsalary LOOP
  FETCH cursorsalary INTO name,sal;
   DBMS_OUTPUT.PUT_LINE(TO_CHAR(name)||' has salary:'|| TO_CHAR(sal));
 END LOOP;

 CLOSE cursorsalary;

END

Source: Steve's blogs http://soa-java.blogspot.com/

Any comments are welcome :)


References:
Oracle PL/SQL Programming

No comments: