DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: About CAST function in oracle

  1. #1
    Join Date
    Aug 2005
    Posts
    1

    About CAST function in oracle

    Hi friends,
    Now iam migrating my system from SQL to ORACLE 9i.

    The sql select query has the following code

    CAST(0 as integer)

    since Oracle doesnt have integer datatype , how should i change the above code??
    should i use number datatype???

    Ex:
    CAST( 0 as number) : Is this correct??? or should i use
    CAST(0 as number(10,0))

    Note: This CASTED value will be stored in a field that is of type INT

    Please help..

  2. #2
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    If you have:
    Code:
    create table t (col1 int);
    then the resultant column is of type NUMBER(38) and you can insert into it any number, and rely on Oracle to round to an integer. If you want to do this before inserting, for some reason, then you could just use the ROUND() function.

    Having said that, this also works if you're more comfortable with it:
    Code:
    SQL> select cast(1.49 as number(38)) from dual;
    
    CAST(1.49ASNUMBER(38))
    ----------------------
                         1
    
    SQL> select cast(1.5 as number(38)) from dual;
    
    CAST(1.5ASNUMBER(38))
    ---------------------
                        2
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width