[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how do i cast string to integer in Oracle

Posted on 2008-11-10
3
Medium Priority
?
9,907 Views
Last Modified: 2012-05-05
folks

how do i cast a string value to integer or float in oracle  ie the value

100.23 is a string field type in table A  and i need to get it into tbale b as a float value using a trigger

all help wil do
0
Comment
Question by:rutgermons
3 Comments
 
LVL 6

Accepted Solution

by:
DocCan11 earned 2000 total points
ID: 22920545
you have two functions available to you .. One is convert

select convert(datatype,value)  

ie select convert(int,mydata)
from test

or you can use to_number

select to_number(data,mask)
from test


The mask help determine the format of the new number.. see the following for a more detailed reference on to_number

http://www.techonthenet.com/oracle/functions/to_number.php
0
 
LVL 15

Expert Comment

by:fsze88
ID: 22921492
try to use to_number function. It is the most easiest way to convert string to be number
more function refers can goto
http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
SQL> select to_number('1234.56') - to_number('234.57') result from dual;
    RESULT
----------
    999.99


SQL> create table abc
  2  (s varchar2(2000));
 
òúËh<.
 
SQL> insert into abc values ('1234.56');
 
òúË 1 Ç™.
 
SQL> commit;
 
ºŒ.
 
SQL> select to_number(s) from abc;
 
TO_NUMBER(S)
------------
     1234.56
 
SQL> select to_number(s) - 234.57 from abc;
 
TO_NUMBER(S)-234.57
-------------------
             999.99

Open in new window

0
 

Author Comment

by:rutgermons
ID: 22974071
Ok thanks

but how do i convert it using a trigger?

TO_NUMBER(:NEW.ITEMQUALITY)

Doesnt work

all help will do
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question