Oracle combines Mybatis to obtain 10 pieces of data from the table

小云云
Release: 2017-12-11 14:38:57
Original
2559 people have browsed it

I have been using mysql and informix databases before. It is very simple to look up the first 10 pieces of data in the table: This article mainly introduces the relevant information of Oracle and Mybatis to achieve the 10 pieces of data from the table. Friends who need it can refer to it. I hope it can help. Everyone.

Original version:

select top * from student
Copy after login


## Of course, we can also write it more complicated, such as adding Some query conditions?

For example, query the top 10 student information with scores greater than 80 points

Added version of where query conditions:

select top * from table where score > 80
Copy after login

but! ! There is no top in Oracle! ! ! ! So how to achieve it?

Well, you can use rownum!

Original version in oracle

select * from student where rownum < 10
Copy after login

There seems to be nothing complicated about the above. . But here comes the question, what if we still want to add a score greater than 80?

For me, an Oracle beginner, it is really laborious. I just posted it here, hoping it can save some people some effort!

Oracle has added a version of where query conditions

select * from( select rownum rn,A.* from student where score > 80) where rn < 10
Copy after login

Briefly analyze the above code. In fact, the data with a score greater than 80 is first queried through the embedded sql statement, and then the first 10 data in the embedded sql query result are selected.

Finally, attach the mybatis code?

Copy after login

The above scores and number are variables

ps: mybatis takes Oracle sequence, the same value problem processing

Copy after login

The above mybatis code always gets the value of the same sequence when called. Query the relevant information and find out that it is the cache of mybatis. Question:

Add

useCache="false" flushCache="false"Attribute:

Copy after login

Related Recommended:


How to change the data file location of the table space in Oracle

How to modify the order of fields in the Oracle database table

oracle query table name and table column name

The above is the detailed content of Oracle combines Mybatis to obtain 10 pieces of data from the table. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!