Oracle 和sql server语法差异

文章对比了Oracle、SQLServer和MySQL在查询数据条数、时间范围查询、字符串连接和截取以及NVL函数的使用上的差异,特别指出了Oracle中rownum的特殊用法和限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Oracle 和sql server语法差异

功能说明sql servermysqlOrcacle
查询数据条数select top 1 * from table_nameselect * from table_name limit 1select * from table_name where rownum=1
时间范围查询select * from table_name where cdate <‘2023-02-05 16:22:44’select * from table_name where cdate <‘2023-02-05 16:22:44’select * from table_name where cdate <to_date(‘2023-02-05 16:22:44’,‘yyyy-mm-dd hh24:mi:ss’) 必须转成时间格式 cdate <to_date(‘2023-02-05’,‘yyyy-mm-dd’) 前后格式必须一致
字符串连接select ‘我’+‘爱’+‘你’ as ILYselect CONCAT(‘我’,‘爱’,‘你’) as ILY 或 select CONCAT_WS(‘我’,‘爱’,‘你’) as ILYselect ‘我’ || ‘爱’ || ‘你’ as ILY from dual
字符串截取select right(‘qwerty’,2)select right(‘qwerty’,2)select substr(‘qwerty’, length(‘qwerty’) - 1) from dual

Oracle 其它注意事项

  1. 执行语句时结尾不允许有“;”,多个执行语句BEGIN end;l包起来
  2. 表名和字段名不能超过30个字符。必须大写
  3. NVL使用 NVL(field,‘’)=‘’ 不可以判断null类型字段,因为’’ 空值默认为null,可以添加默认值来判断NVL(field,‘0’)=‘0’
  4. select * from table_name where rownum=1 order by CreationTime desc,Oracle查询机制是先查询rownum条件数据,根据查询的数据在进行排序,所有需要包一层排序查询,再去rownum的数据,select * from (select * from table_name where 1=1 order by CreationTime desc)a where rownum=1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值