Reputation: 15552
I am using Oracle and have a table containing a long datatype. I have since discovered that this is legacy and I should have used a LOB. I also now think I could probably just use NUMBER(10,0).
I want to convert the column from a long datatype to a NUMBER datatype.
Here is my SQL so far.
ALTER TABLE BUDGET ADD AMT2 NUMBER(10,0);
UPDATE BUDGET SET AMT2 = AMT;
ALTER TABLE BUDGET DROP COLUMN AMT;
ALTER TABLE BUDGET RENAME COLUMN AMT2 TO AMT;
The AMT columns is LONG The new AMT2 column is my new column of NUMBER(10, 0)
The problem is that when assigning the long to a number I get an error. This is on the update line (line2) This I presume is because of data truncation.
The error is
SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got LONG
All the data in the column is less than 10000 so I want to force oracle to ignore any data truncation (because I dont believe there should be any). How can I assign the long data to a number data column?
Thanks
Upvotes: 1
Views: 3006
Reputation: 594
Create a PL/SQL Function to get the Long as the data-type you need.
Example:
create or replace
function longtonumber( p_rowid in rowid)
return number
as
l_data long;
begin
select remarks into l_data from cr_claimheader where rowid = p_rowid;
return to_number(substr( l_data, 1, 4000 ));
end;
Then all you need to do is update using this function in your update statement: update am1=longtonumber(amt2)...etc.
I got this from askTom: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:839298816582
Upvotes: 4