Home  >  Article  >  Database  >  Oracle中的内置函数在sql中的转换整理

Oracle中的内置函数在sql中的转换整理

WBOY
WBOYOriginal
2016-06-07 17:42:36752browse

程序里面经常会即支持Oracle数据库,又支持sql数据库。而有些Oracle内置函数用的比较多,但在sql中语法有些不同,我做了些整理,希望可以帮助大家。。。。 1.oracle中的内置函数: oracle 中的round函数(四舍五入)(sql也可以用) oracle 中的trunc返回的

程序里面经常会即支持Oracle数据库,又支持sql数据库。而有些Oracle内置函数用的比较多,香港空间,但在sql中语法有些不同,我做了些整理,网站空间,希望可以帮助大家。。。。

 

1.oracle中的内置函数:
oracle 中的round函数(四舍五入)(sql也可以用)
oracle 中的trunc返回的是当天日期的[00:00:00]
oracle 中的floor,floor(n)取小于等于数值n的最大整数(sql也可以用)
oracle 中的length函数 sqlserver中是len
oracle 中的datalength函数 sqlserver中是datalength
oracle 中的lob_to_char函数 改为convert(char,opertime,120)
oracle 中的to_char函数 改为convert(char,opertime,120)
oracle 中的substr函数 改为substring
例如:select convert(char, getdate(), 120) --yyyy-mm-dd hh:mm:ss(24h)
convert(char,SubmitTime,120)= convert(char,getdate(),120)
oracle 中floor(sysdate - trunc(opertime)改为 datediff(dd,convert(varchar(100),InputDate,111),convert(varchar(100),getdate(),111))
oracle 中的dbms_lob.getlength改为datalength(sqlserver数据库中把Clob类型改为NText类型)
oracle 中的 ROWNUM改为row_number() OVER(ORDER BY xx)并且sql语句中必须带有top
例如:sql中的写法:
SELECT * FROM (
SELECT A.*, row_number() OVER(ORDER BY A.MATTERID ) as RN FROM (
SELECT * FROM ATTACHMENT_T ) A
)T WHERE RN =0

 

2.Oacle系统表 dual
证对sqlserver直接去掉dual

 

3.遇到的错误以及解决方法:
SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间
修改model里面的构造函数,服务器空间,给属性赋值为DateTime类型
ElementContent_Model,OperLog_Model

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn