Oracle combines mybatis for table Top 10

Source: Internet
Author: User

Before using MySQL and Informix databases, it is easy to look up the first 10 data in a table:

Most original version:

Select Top *  from Student

Of course, we can also write a bit more complex, such as some additional query conditions?

For example, query the first 10 students with scores greater than 80 points

Added version of where query condition:

Select Top *  from Table where >  the

But!! There is no top in Oracle!!!! So how do we do that?

Well, you can use rownum!.

Original version in Oracle

Select *  from where < Ten

There seems to be no complicated place up there. But the question is, if we still want to add a score greater than 80?

It's really hard for me, the Oracle beginner. Here directly posted out, hope can let some people less cost some force!

Oracle adds a where query condition version

Select *  from (        Select rownum rn,a.*fromwhere>  where<Ten

Simply analyze the above code. In fact, the first 10 data in the embedded SQL query result is queried by the embedded SQL statement, and then the data with the score greater than 80 is selected.

Finally attach MyBatis code?

<SelectId="Selectstudent" ParameterType="HashMap" Resultmap="Baseresultmap">     Select *      from (        SelectRowNum RN, A.*  fromStudent AwhereSTATUS= ' About'         andScore<![cdata[>]]>#{scores,jdbctype=INTEGER})      whereRn<![cdata[<=]]>#{ Number, Jdbctype=INTEGER}  </Select>

The above scores and number are variables

It's a little bit of a broken-down reading. I hope I can help you meet the same problem with my friends.

Oracle combines mybatis for table Top 10

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.