Oracle,mysql,sqlserver,postgresql语句几点比較
Posted llguanli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle,mysql,sqlserver,postgresql语句几点比較相关的知识,希望对你有一定的参考价值。
1.分页
Oracle: SELECT * FROM(SELECT A.*, ROWNUM RN FROM (select T.* from sj_receiptinfo t WHERE t.TAXNO LIKE CONCAT(‘%‘, CONCAT(?, ‘%‘)) order by t.id desc) A WHERE ROWNUM <= ?
)WHERE RN > ?
mysql:
select * from tableName where 条件
sqlServer: SELECT w2.n, w1.* FROM ARTICLE w1,( SELECT TOP 1030 row_number() OVER (ORDER BY YEAR DESC, ID DESC) n, ID FROM ARTICLE) w2 WHERE w1.ID = w2.ID AND w2.n > 1000 ORDER BY w2.n ASC
postgresql:select * from xxx limit pagesize offset offsetNum ;
pagesize是固定的,即每页显示多少记录。
offsetNum=(当前页数-1)*pagesize
2.查询头5条记录
Oracle: SELECT * FROM PersonsWHERE ROWNUM <= 5
mysql: SELECT * FROM Persons LIMIT 5
sqlServer: SELECTTOP 2
* FROM Personspostgresql:SELECT * FROM Persons LIMIT 5。跟mysql一样
3.模糊查询
Oracle:select T.* from sj_receiptinfo t WHERE t.TAXNO LIKE CONCAT(‘%‘, CONCAT(?
, ‘%‘))
mysql:select T.* from sj_receiptinfo t WHERE t.TAXNO LIKE CONCAT(‘%‘, ?, ‘%‘)
sqlServer:select T.* from sj_receiptinfo t WHERE t.TAXNO LIKE ‘%%’
postgresql:select *。( T .类别代码 || ‘-‘ || T .发票号码 ) AS 号码 from account where username ~* ‘baidu‘;
找出数据表account中全部用户名包括baidu且不区分大写和小写的用户的信息
4.推断null
Oracle:SELECT ProductName,UnitPrice*(UnitsInStock+NVL(UnitsOnOrder,0))FROM Products
mysql:SELECT ProductName,UnitPrice*(UnitsInStock+IFNULL(UnitsOnOrder,0))FROM Products
sqlServer:SELECT ProductName,UnitPrice*(UnitsInStock+ISNULL(UnitsOnOrder,0))FROM Products
postgresql:SELECT ProductName,UnitPrice*(UnitsInStock+COALESCE(UnitsOnOrder,0))FROM Products
5.插入数据
Oracle:insert into company(id,name,parentid,ccdm) values(COMPANY_SEQ.NEXTVAL,?
,?,?
)序列
mysql:insert into person(fullName,companyName) values(?,?) 由于ID是自己主动增长auto_increment
6.查询最大id
Oracle:SELECT NVL(MAX(ID),0)+1 FROM REPOT_BS
以上是关于Oracle,mysql,sqlserver,postgresql语句几点比較的主要内容,如果未能解决你的问题,请参考以下文章
oracle ,mysql 和sqlserver的主要区别都有哪些?
sqlserver,oracle,mysql等的driver驱动,url怎么写
sqlserver,oracle,mysql等的driver驱动,url怎么写