Oracle 和sql server语法差异
功能说明 | sql server | mysql | Orcacle |
---|---|---|---|
查询数据条数 | select top 1 * from table_name | select * from table_name limit 1 | select * 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 ILY | select CONCAT(‘我’,‘爱’,‘你’) as ILY 或 select CONCAT_WS(‘我’,‘爱’,‘你’) as ILY | select ‘我’ || ‘爱’ || ‘你’ as ILY from dual |
字符串截取 | select right(‘qwerty’,2) | select right(‘qwerty’,2) | select substr(‘qwerty’, length(‘qwerty’) - 1) from dual |
Oracle 其它注意事项
- 执行语句时结尾不允许有“;”,多个执行语句BEGIN end;l包起来
- 表名和字段名不能超过30个字符。必须大写
- NVL使用 NVL(field,‘’)=‘’ 不可以判断null类型字段,因为’’ 空值默认为null,可以添加默认值来判断NVL(field,‘0’)=‘0’
- 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