Thursday, January 10, 2013

Cast Function


In Oracle/PLSQL, the cast function converts one datatype to another.

Syntax

The syntax for the cast function is:
cast ( { expr | ( subquery ) | MULTISET ( subquery ) } AS type_name )

Note

The following casts are allowed:
TOFROM
char, varchar2numberdatetime / intervalrawrowid, urowidnchar, nvarchar2
char, varchar2XXXXX 
numberXX    
datetime / intervalX X   
rawX  X  
rowid, urowidX   X 
nchar, nvarchar2 XXXXX

Applies To

  • Oracle 11g, Oracle 10g, Oracle 9i

For Example

select cast( '22-Aug-2003' AS varchar2(30) )
from dual;
This would convert the date (ie: 22-Aug-2003) into a varchar2(30) value.