本文翻译自:Convert INT to VARCHAR SQL
I am using Sybase and I am doing a select which returns me a column called "iftype", but its type is int and I need to convert into varchar. 我正在使用Sybase,我正在做一个select,它返回一个名为“iftype”的列,但它的类型是int,我需要转换为varchar。 When I try to do the select without the convert function I get this error: 当我尝试在没有转换功能的情况下进行选择时,我收到此错误:
Error code 257, SQL state 37000: Implicit conversion from datatype 'VARCHAR' to 'INT' is not allowed. 错误代码257,SQL状态37000:不允许从数据类型“VARCHAR”到“INT”的隐式转换。 Use the CONVERT function to run this query. 使用CONVERT函数运行此查询。
I dont know how to implement the function CONVERT
. 我不知道如何实现CONVERT
函数。 Can anyone help me, please ? 有人可以帮帮我吗?
#1楼
参考:https://stackoom.com/question/1LpaW/将INT转换为VARCHAR-SQL
#2楼
使用转换功能。
SELECT CONVERT(varchar(10), field_name) FROM table_name
#3楼
Use the STR
function: 使用STR
功能:
SELECT STR(field_name) FROM table_name
Arguments 参数
float_expression float_expression
Is an expression of approximate numeric (float) data type with a decimal point. 是具有小数点的近似数值(浮点)数据类型的表达式。
length 长度
Is the total length. 是总长度。 This includes decimal point, sign, digits, and spaces. 这包括小数点,符号,数字和空格。 The default is 10. 默认值为10。
decimal 十进制
Is the number of places to the right of the decimal point. 是小数点右边的位数。 decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point. decimal必须小于或等于16.如果decimal小于16,则结果将被截断为小数点右侧的16位。
source: https://msdn.microsoft.com/en-us/library/ms189527.aspx 来源: https : //msdn.microsoft.com/en-us/library/ms189527.aspx
#4楼
您可以使用CAST
功能:
SELECT CAST(your_column_name AS varchar(10)) FROM your_table_name