Access911.net   |   a9BBS   |   OTaA System  
  搜索文章:  
Access911欢迎您光临  
   主页      上传      繁體版       论坛     
设为首页  |  加入收藏   
  
你现在的位置:文章索引 -> 文章分类 -> 函数  
 首页|  近日更新|  下载  |  文章索引  |  搜索|  术语|  承接工程|  
 
系统正在加载内容,请耐心等待...
 
 查询
 窗体
 报表
 
 
 VBA
 函数
 ADO/DAO/ADO.NET
 API
 ADP
 安全
 发布
 OA
 ASP/ASP.NET
 其他语言
 控件
 DELPHI
 C#/.Net
 本站
 其他
 小例程
 常用软件
 参考文档
 业主作品
 网友大作
 
 
友情链接
 access911.net
 
访问人次
 1702235
 
站长 E-Mail
 net911@sina.com
 access911@gmail.com
 
RSS 订阅

显示附加信息 >>>

ODBC标量函数(5)(英文)——数据类型转换函数

作者:MS  摘自:Microsoft  :cg1  更新日期:2004-7-13  浏览人次:

 

Explicit Data Type Conversion Function

Explicit data type conversion is specified in terms of SQL data type definitions.

The ODBC syntax for the explicit data type conversion function does not restrict conversions. The validity of specific conversions of one data type to another data type will be determined by each driver-specific implementation. The driver will, as it translates the ODBC syntax into the native syntax, reject those conversions that, although legal in the ODBC syntax, are not supported by the data source. The ODBC function SQLGetInfo, with the conversion options (such as SQL_CONVERT_BIGINT, SQL_CONVERT_BINARY, SQL_CONVERT_INTERVAL_YEAR_MONTH, and so on), provides a way to inquire about conversions supported by the data source.

The format of the CONVERT function is:

CONVERT(value_exp, data_type)

The function returns the value specified by value_exp converted to the specified data_type, where data_type is one of the following keywords:

SQL_BIGINT SQL_INTERVAL_HOUR_TO_MINUTE
SQL_BINARY SQL_INTERVAL_HOUR_TO_SECOND
SQL_BIT SQL_INTERVAL_MINUTE_TO_SECOND
SQL_CHAR SQL_LONGVARBINARY
SQL_DECIMAL SQL_LONGVARCHAR
SQL_DOUBLE SQL_NUMERIC
SQL_FLOAT SQL_REAL
SQL_GUID SQL_SMALLINT
SQL_INTEGER SQL_DATE
SQL_INTERVAL_MONTH SQL_TIME
SQL_INTERVAL_YEAR SQL_TIMESTAMP
SQL_INTERVAL_YEAR_TO_MONTH SQL_TINYINT
SQL_INTERVAL_DAY SQL_VARBINARY
SQL_INTERVAL_HOUR SQL_VARCHAR
SQL_INTERVAL_MINUTE SQL_WCHAR
SQL_INTERVAL_SECOND SQL_WLONGVARCHAR
SQL_INTERVAL_DAY_TO_HOUR SQL_WVARCHAR
SQL_INTERVAL_DAY_TO_MINUTE  
SQL_INTERVAL_DAY_TO_SECOND  

The ODBC syntax for the explicit data type conversion function does not support specification of conversion format. If specification of explicit formats is supported by the underlying data source, a driver must specify a default value or implement format specification.

The argument value_exp can be a column name, the result of another scalar function, or a numeric or string literal. For example:

{ fn CONVERT( { fn CURDATE() }, SQL_CHAR ) }

converts the output of the CURDATE scalar function to a character string.

Because ODBC does not mandate a data type for return values from scalar functions (because the functions are often data source–specific), applications should use the CONVERT scalar function whenever possible to force data type conversion.

The following two examples illustrate the use of the CONVERT function. These examples assume the existence of a table called EMPLOYEES, with an EMPNO column of type SQL_SMALLINT and an EMPNAME column of type SQL_CHAR.

If an application specifies the following SQL statement:

SELECT EMPNO FROM EMPLOYEES WHERE {fn CONVERT(EMPNO,SQL_CHAR)} LIKE '1%'
  • A driver for ORACLE translates the SQL statement to:
    SELECT EMPNO FROM EMPLOYEES WHERE to_char(EMPNO) LIKE '1%'
  • A driver for SQL Server translates the SQL statement to:
    SELECT EMPNO FROM EMPLOYEES WHERE convert(char,EMPNO) LIKE '1%'

If an application specifies the following SQL statement:

SELECT {fn ABS(EMPNO)}, {fn CONVERT(EMPNAME,SQL_SMALLINT)}
   FROM EMPLOYEES WHERE EMPNO <> 0
  • A driver for ORACLE translates the SQL statement to:
    SELECT abs(EMPNO), to_number(EMPNAME) FROM EMPLOYEES WHERE EMPNO <> 0
  • A driver for SQL Server translates the SQL statement to:
    SELECT abs(EMPNO), convert(smallint, EMPNAME) FROM EMPLOYEES
       WHERE EMPNO <> 0
  • A driver for Ingres translates the SQL statement to:
    SELECT abs(EMPNO), int2(EMPNAME) FROM EMPLOYEES WHERE EMPNO <> 0

 

 
相关文章
     没有手动相关文章
     ODBC标量函数(6)(英文)——SQL 92 CAST 函数
     ODBC标量函数(4)(英文)——系统函数
     ODBC标量函数(3)(英文)——日期时间函数
     ODBC标量函数(2)(英文)——数值函数
     ODBC标量函数(1)(英文)——字符串
 
评论
     查看或发表更多的评论,请单击这里。
 
 
 
 
 
   
  Access911.net   |   a9BBS   |   OTaA System   |
建站日期:2000年4月2日  |  设计施工:陈格 ( access911 & cg1 )
 Copyright © 2000 - 2003 COMET, 陈格 保留所有权利