oracle string integer,在oracle中將字符串轉換為整數

I am trying to parse a column of strings in Oracle (version 8i) to an integer.

我試圖將Oracle(版本8i)中的一列字符串解析為整數。

I am accessing the results through Oracle.DataAccess library

我通過Oracle.DataAccess庫訪問結果

I'm already using TO_NUMBER with a mask to convert the string into a number with no decimal places. The problem is that the value in the client code is being retrieved as a decimal rather than an int.

我已經使用帶掩碼的TO_NUMBER將字符串轉換為沒有小數位的數字。問題是客戶端代碼中的值是以十進制而不是int的形式檢索的。

4 个解决方案

#1

NUMBER columns always come back as decimals in ODP.NET. To get around this, pull it back as an OracleDecimal, which has several "Toxxxx" methods to cast the value into the native .NET type you need.

在ODP.NET中,NUMBER列總是以小數形式返回。為了解決這個問題,請將其作為OracleDecimal拉回來,它有幾個“Toxxxx”方法將值轉換為您需要的本機.NET類型。

while (myOracleDataReader.Read())

{

int x = myOracleDataReader.GetOracleDecimal(0).ToInt32();

}

(Forgive me if the code above isn't 100% correct, as I don't have ODP.NET installed at home.)

(如果上面的代碼不是100%正確,請原諒我,因為我家里沒有安裝ODP.NET。)

#2

CAST(field AS integer)

#3

TO_NUMBER is what you want, specifically the TO_NUMBER('42', '99') version.

TO_NUMBER是您想要的,特別是TO_NUMBER('42','99')版本。

#4

You can always turn the decimal into an integer using the round function (or the trunc or floor functions)

您始終可以使用round函數(或trunc或floor函數)將小數轉換為整數

你可能感兴趣的:(oracle,string,integer)