Comparison of Oracle,mysql,sqlserver,postgresql statements

Source: Internet
Author: User
Tags postgresql

1. Paging

Oracle: SELECT * FROM (select A.*, ROWNUM RN from (select t.* to Sj_receiptinfo T WHERE t.taxno like CONCAT ('% ', CONCAT (?, '% ')) ORDER BY t.id Desc) A WHERE ROWNUM <=?

) WHERE RN >?


MySQL: SELECT * from TableName where conditions Limit( Current page number*page Capacity-1) , page Capacity pagesize


SQL Server : Select W2.N, w1.* from article W1, (select TOP 1030 row_number () Up (ORDER by year DESC, id DESC) n, id from article) W2 WHERE w1.id = w2.id and W2.N > ORDER by W2.N ASC


PostgreSQL: select * from xxx limit pagesize offset offsetnum;

The pagesize is fixed, that is, how many records are displayed per page.

offsetnum= (Current page-1) *pagesize



2. Query Header 5 Records

oracle: select * &NBSP; from Persons where ROWNUM <= 5

MySQL:LIMIT 5
SQL Server  :  TOP 2 * from Persons
PostgreSQL:  SELECT * from Persons LIMIT 5. Just like MySQL .
3. Fuzzy query
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 ('% ',? , '% ')

Sql server:
Select t.* from Sj_receiptinfo T WHERE t.taxno like '% '
PostgreSQL:  SELECT *. (T. Category Code | | '-' | | T. Invoice number) as number from the account where username ~* ' Baidu ';
Find information about all user names in the data table account, including Baidu and those that do not distinguish between uppercase and lowercase
4. Infer null
Oracle: SELECT productname,unitprice* (unitsinstock+NVL(unitsonorder,0))  from Products
MySQL: SELECT productname,unitprice* (unitsinstock+ifnull(unitsonorder,0))  from Products
SQL Server: SELECT productname,unitprice* (unitsinstock+ISNULL(unitsonorder,0))  from Products
PostgreSQL: SELECT productname,unitprice* (unitsinstock+coalesce(unitsonorder,0))  from Products
5. Inserting data
Oracle: INSERT INTO Company (ID,NAME,PARENTID,CCDM) VALUES (company_seq. Nextval, huh?

,?,?

) sequence

MySQL:insert into person (fullname,companyname) VALUES (?,?) because the ID is self-actively growing auto_increment
6. Query the maximum ID
Oracle:SELECTNVL (MAX(ID), 0) +1 fromRepot_bs

Comparison of Oracle,mysql,sqlserver,postgresql statements

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.