Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Day 54: PL/Sql - 2 (%Type)

Nov 6 2011 8:28AM by Niladri Biswas   

%TYPE

Say we have a table as under

Create Table tblEmployee
(
	EmpName VARCHAR2(50)
	,Salary INT
);

It is a simple table with two columns viz. EmpName of type VARCHAR2 and Salary of Type INT

Consider we have variables for holding the datatype of a table's column.


DECLARE
	var_EmpName  VARCHAR(50) := 'TestEmp';
	var_Salary INT ;
BEGIN
	/* Some PL/SQLcode */
	Select Salary
	Into var_Salary
	From tblEmployee
	Where EmpName = var_EmpName;

END;

We can make out that we are storing the Salary record in the var_Salary field for a particular employee. Now imagine that we have many store procedures where we need to define the 'var_Salary' as INT. Now because of some business need, we need to change the initial datatype of the field 'Salary' from INT to NUMBER as under

Alter Table tblEmployee
Modify ( Salary Number(7,2));

Now imagine the pain of changing the datatype of 'var_Salary' from INT to NUMBER in all those stored procedures where it has been used. For eleiminating this problem, we have %TYPE. It specifies the type to the variable same as specified for the column and accomodate changes made in the colunn data types.

DECLARE
 var_EmpName tblEmployee.EMPNAME%TYPE := 'TestEmp';
 var_Salary tblEmployee.SALARY%TYPE;
BEGIN
 /* Some PL/SQLcode */
 Select Salary
 Into var_Salary
 From tblEmployeetest
 Where EmpName = var_EmpName;
 DBMS_OUTPUT.PUT_LINE(var_Salary);
END;
/

As can be figure out that, now the variables are strictly typed.

The general syntax can be: Variable_Name Table_Name.Column_Name%Type

Hope this is useful.Thanks for reading

Tags: SQL Server, Oracle, #SQL SERVER,


Niladri Biswas
7 · 21% · 6710
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Day 54: PL/Sql - 2 (%Type)" rated 5 out of 5 by 1 readers
Day 54: PL/Sql - 2 (%Type) , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]