添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

一、SQL数据类型转换代码

SELECT CAST('3.02' as decimal) 
-- they aren't real decimals in sqlite, though. beware floats. 

二、sqlite数据类型转换参考

Affinity of type-name

Conversion Processing   转换处理

NONE

没有

Casting a value to a type-name with no affinity causes the value to be converted into a BLOB. Casting to a BLOB consists of first casting the value to TEXT in the encoding of the database connection, then interpreting the resulting byte sequence as a BLOB instead of as TEXT.

将一个值转换为一个 类型名称 没有关联将导致值转换为BLOB。强制转换为BLOB包括首先将值强制转换为 编码 然后将结果字节序列解释为BLOB而不是文本。

TEXT

文本

To cast a BLOB value to TEXT, the sequence of bytes that make up the BLOB is interpreted as text encoded using the database encoding.

Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the encoding of the database connection.

若要将BLOB值强制转换为文本,组成BLOB的字节序列将被解释为使用数据库编码的文本编码。将整数值或实数值强制转换为文本将使该值如同通过 sqlite3\u snprintf() 除了结果文本使用 编码 数据库连接的名称。

REAL

When casting a BLOB value to a REAL, the value is first converted to TEXT.

When casting a TEXT value to REAL, the longest possible prefix of the value that can be interpreted as a real number is extracted from the TEXT value and the remainder ignored. Any leading spaces in the TEXT value are ignored when converging from TEXT to REAL. If there is no prefix that can be interpreted as a real number, the result of the conversion is 0.0.

将BLOB值强制转换为实数时,首先将该值转换为文本。

将文本值强制转换为实数时,将从文本值中提取可解释为实数的值的最长前缀,并忽略其余部分。从文本聚合到实数时,将忽略文本值中的任何前导空格。如果没有可以解释为实数的前缀,则转换的结果为0.0。

INTEGER

整数

When casting a BLOB value to INTEGER, the value is first converted to TEXT.

When casting a TEXT value to INTEGER, the longest possible prefix of the value that can be interpreted as an integer number is extracted from the TEXT value and the remainder ignored. Any leading spaces in the TEXT value when converting from TEXT to INTEGER are ignored. If there is no prefix that can be interpreted as an integer number, the result of the conversion is 0. If the prefix integer is greater than +9223372036854775807 then the result of the cast is exactly +9223372036854775807. Similarly, if the prefix integer is less than -9223372036854775808 then the result of the cast is exactly -9223372036854775808.

When casting to INTEGER, if the text looks like a floating point value with an exponent, the exponent will be ignored because it is no part of the integer prefix. For example, "(CAST '123e+5' AS INTEGER)" results in 123, not in 12300000.

The CAST operator understands decimal integers only — conversion of hexadecimal integers stops at the "x" in the "0x" prefix of the hexadecimal integer string and thus result of the CAST is always zero.

A cast of a REAL value into an INTEGER results in the integer between the REAL value and zero that is closest to the REAL value. If a REAL is greater than the greatest possible signed integer (+9223372036854775807) then the result is the greatest possible signed integer and if the REAL is less than the least possible signed integer (-9223372036854775808) then the result is the least possible signed integer.

Prior to SQLite version 3.8.2 (2013-12-06), casting a REAL value greater than +9223372036854775807.0 into an integer resulted in the most negative integer, -9223372036854775808. This behavior was meant to emulate the behavior of x86/x64 hardware when doing the equivalent cast.

将BLOB值强制转换为整数时,首先将该值转换为文本。

将文本值强制转换为整数时,将从文本值中提取可解释为整数的值的最长前缀,并忽略余数。从文本转换为整数时,文本值中的任何前导空格都将被忽略。如果没有可解释为整数的前缀,则转换结果为0。如果前缀整数大于+9223372036854775807,则强制转换的结果正好是+9223372036854775807。类似地,如果前缀整数小于-9223372036854775808,则强制转换的结果正好是-9223372036854775808。

强制转换为整数时,如果文本看起来像带指数的浮点值,则指数将被忽略,因为它不是整数前缀的一部分。例如,“(将'123e+5'转换为整数)”结果是123,而不是12300000。

CAST运算符只理解十进制整数-的转换 十六进制整数 在十六进制整数字符串的“0x”前缀中的“x”处停止,因此强制转换的结果始终为零。

将实值转换为整数将导致实值和零之间的整数最接近实值。如果实数大于最大可能有符号整数(+9223372036854775807),则结果为最大可能有符号整数,如果实数小于最小可能有符号整数(-9223372036854775808),则结果为最小可能有符号整数。

在SQLite版本3.8.2(2013-12-06)之前,将大于+9223372036854775807.0的实值强制转换为整数会导致最负的整数-9223372036854775808。此行为旨在模拟执行等效转换时x86/x64硬件的行为。

NUMERIC

数字

Casting a TEXT or BLOB value into NUMERIC yields either an INTEGER or a REAL result. If the input text looks like an integer (there is no decimal point nor exponent) and the value is small enough to fit in a 64-bit signed integer, then the result will be INTEGER. Input text that looks like floating point (there is a decimal point and/or an exponent) and the text describes a value that can be losslessly converted back and forth between IEEE 754 64-bit float and a 51-bit signed integer, then the result is INTEGER. (In the previous sentence, a 51-bit integer is specified since that is one bit less than the length of the mantissa of an IEEE 754 64-bit float and thus provides a 1-bit of margin for the text-to-float conversion operation.) Any text input that describes a value outside the range of a 64-bit signed integer yields a REAL result.

Casting a REAL or INTEGER value to NUMERIC is a no-op, even if a real value could be losslessly converted to an integer.

将文本或BLOB值转换为数字将产生整数或实数结果。如果输入文本看起来像一个整数(没有小数点或指数),并且该值足够小,可以容纳64位有符号整数,那么结果将是整数。输入看起来像浮点的文本(有一个小数点和/或一个指数),该文本描述了一个值,该值可以在IEEE 754 64位浮点和51位有符号整数之间无损地来回转换,然后结果是整数(在前面的句子中,指定了一个51位整数,因为它比ieee754 64位浮点的尾数长度少一位,因此为文本到浮点的转换操作提供了1位的余量。)任何描述64位有符号整数范围之外的值的文本输入都会产生一个实际结果。

将实数或整数值转换为数值是不可操作的,即使实数可以无损地转换为整数。

decimal

十进制

@num=1; 把num类型 成nvarchar类型 cast(@num as nvarchar(10)) @str=’123′; 把str 换成int 类型 cast(@str as int) 您可能感兴趣的文章:详解SQL Server中的 数据 类型详解MySQL 数据 类型int(M)中M的含义mysql存储引擎和 数据 类型(二)Java 数据 类型与MySql 数据 类型对照表SQL Server 数据 类型转换 方法SQL Server比较常见 数据 类型详解 SQLite 教程(七): 数据 类型详解SQL Server 数据 类型char、nchar、varchar、n 表:JobInfo 表内字段:Salary  薪水 select * from JobInfo where cast(substr(Salary,1,5)as int)>10000 是否可以在My SQL查询 中将文本 换为 数字 ? 我有一列带有标识符的列,该标识符由名称和 数字 组成,格式为"名称- 数字 "。 该列具有VARCHAR类型。 我想根据 数字 (具有相同名称的行)对行进行排序,但是根据do字符顺序对列进行排序,即name-1name-11name-12name-2如果我减少了 数字 ,是否可以将" varchar" 数字 换为"真实" 数字 并用它对行进行排序? 我想获得以下订单。nam... 日期时间 字符串 Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06 Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16 Select CONVERT(varchar... I am aware that there are functions in Oracle and MsSQl that can do so, so is there any function that does it or is there any way to convert it inside sqlite ?My table structure;col1 primary key intcol... —创建 备份 数据 的 device USE master EXEC sp_addumpdevice ‘disk’, ‘testBack’, ‘c:\mssql7backup\MyNwind_1.dat’ — 开始 备份 BACKUP DATABASE pubs TO testBack 4、说明:创建新 convert(varchar,日期,日期样式编码) select GETDATE() 前,‘date:’+CONVERT(varchar,GETDATE(),106) 后 前 后 2022-02-18 11:38:52.970 date:18 02 这是我写的一个计算回访率(%)的表达式:cast(cast(t8.back as decimal)/cast((t8.back + t9.noback) as decimal)as decimal) as 回访率(%) 我得到的值是0,(t8.back=3,t8.back + t9.noback=5;)想请问高手们,怎样才能获取的值为0.6啊非常感谢!!!!急!!!! com_id, customer_id, corp_sim_name, ( case when tel_no is NULL then '' else ltrim(rtrim(tel_no)) end ) ... /*打开一个 数据 库,如果已经存在直接打开,否则会创建一个*/ 1 int sqlite 3_open( const char *filename,/*这个是 数据 库的文件名*/ sqlite 3 **ppDb/*要带回的 数据 库句柄*/ /*关闭句柄*/ 2)int sqlite 3_close( sqlite 3 *p