Home » SQL & PL/SQL » SQL & PL/SQL » Cast 1 as integer
icon6.gif  Cast 1 as integer [message #221694] Wed, 28 February 2007 01:48 Go to next message
orahome
Messages: 2
Registered: February 2007
Junior Member
What is diffrence between

select cast('column_name' as integer)/10 from table;
and
select column_name/10 from table;

Laughing and column_name is having varchar2 datatype.
Re: Cast 1 as integer [message #221710 is a reply to message #221694] Wed, 28 February 2007 02:37 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Well, the first one will fail every time, with an Invalid Number error, as you're trying to convert the string 'column_name' into an integer.

Both of them are a very bad idea, as you've got no guarantee that the column you're working on contains only numeric data.

Other than that, they're the same.
Re: Cast 1 as integer [message #221921 is a reply to message #221710] Thu, 01 March 2007 01:39 Go to previous messageGo to next message
orahome
Messages: 2
Registered: February 2007
Junior Member
no first one is also executed if it contains numeric data.
so what is the use of cast function.
Re: Cast 1 as integer [message #221939 is a reply to message #221921] Thu, 01 March 2007 03:22 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
I'm sorry - I don't think you're executing the same code that you posted.
Here's what happens when you run the code that you posted:
select cast('column_name' as integer)/10 from dual
            *
ERROR at line 1:
ORA-01722: invalid number


Now, if you remove the single quotes from around 'column_name', then it will behave in the same fashion as the second example.
Previous Topic: Query Help with Large Table
Next Topic: Store and Manipulate pdf in Oracle 9i
Goto Forum:
  


Current Time: Sat Dec 10 14:22:20 CST 2016

Total time taken to generate the page: 0.16004 seconds