Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to fetch the first 10 pieces of data in the table by Oracle combined with Mybatis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how Oracle combined with Mybatis to achieve access to the first 10 pieces of data in the table, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Previously, I have been using mysql and informix databases, and looking up the first 10 pieces of data in the table is very simple:

Original version:

Select top * from student

Of course, we can also write a little more complicated, such as adding some query conditions?

For example, query the information of the first 10 students whose scores are greater than 80.

A version of the where query condition was added:

Select top * from table where score > 80

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 上面这个好像也没有复杂的地方。。但是问题来了,如果我们还希望加上分数大于80呢? 对于我这个oracle初学者来说,真的是费力。在这里就直接贴出来了,希望可以让一些人少费一些力! oracle添加了where查询条件的版本 select * from( select rownum rn,A.* from student where score >

80) where rn

< 10 简单分析一下上面的代码。实际上是先通过内嵌的sql语句查询出分数大于80的数据,再选择内嵌sql查询结果中的前10条数据 最后附上mybatis代码? select * from ( select rownum rn, A.* from student A where STATUS = '99' and score ]]>

# {scores,jdbcType=INTEGER}) where rn # {number,jdbcType=INTEGER}

Both scores and number above are variables

Ps:mybatis takes Oracle sequence and deals with the problem with the same value.

Select 'TRD' | | to_char (sysdate,'yyyymmdd') | | lpad (to_char (SQ_ORD_PURCHASE_ID.nextval), 5,' 0') code from dual

The above mybatis code always gets the value of the same sequence when calling. Query the relevant information and know that it is the cache problem of mybatis:

Add the useCache= "false" flushCache= "false" attribute to:

Select 'TRD' | | to_char (sysdate,'yyyymmdd') | | lpad (to_char (SQ_ORD_PURCHASE_ID.nextval), 5,' 0') code from dual is all the contents of the article "how to fetch the first 10 pieces of data in a table with Oracle and Mybatis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report