当前位置:网站首页>Solve the problem that Oracle cannot use more than 1000 in statements
Solve the problem that Oracle cannot use more than 1000 in statements
2022-07-28 05:41:00 【CTRL Trainee - brother Xie blog】
stay oracle in , Use in Method when querying records , If in The number of subsequent parameters exceeds 1000 individual , Then there will be mistakes ,JDBC Will throw out “java.sql.SQLException: ORA-01795: The maximum number of expressions in the list is 1000” This anomaly .
List of articles
Here's my solution :
One 、 Create temporary tables
ORACLE There are two types of temporary tables : Session level temporary tables and transaction level temporary tables .
1、ON COMMIT DELETE ROWS
It is the default parameter of the temporary table , Indicates that the data in the temporary table is only in the process of transaction (Transaction) Effective in , When a transaction commits (COMMIT) after , The temporary segment of the temporary table will be automatically truncated (TRUNCATE), But the structure of the temporary table And metadata is also stored in the user's data dictionary . If the temporary table completes its mission , It's best to delete the temporary table , Otherwise, the database will leave a lot of table structure and metadata of temporary tables .
2、ON COMMIT PRESERVE ROWS
It means that the contents of the temporary table can exist across transactions , however , When the session ends , The temporary segment of the temporary table will be discarded with the end of the session , The data in the temporary table is naturally discarded . But the structure and metadata of the temporary table are also stored in the user's data dictionary . If the temporary table completes its mission , It's best to delete the temporary table , Otherwise, the database will leave a lot of table structure and metadata of temporary tables .
create global temporary table test_table
(id varchar2(50), name varchar2(10))
on commit preserve rows; -- Create a temporary table ( Current session effective )
-- Add data
insert into test_table VALUES('ID001', 'xgg');
insert into test_table VALUES('ID002', 'xgg2');
select * from test_table; -- Query data
TRUNCATE TABLE test_table; -- Empty temporary table data
DROP TABLE test_table; -- Delete temporary table
After creating the temporary table ,in Sub query can be used in the statement , So there won't be more than 1000 Wrong report
select * from table_name where id in(select id from test_table);
Two 、 Use in() or in()
The official said : A comma-delimited list of expressions can contain no more than 1000 expressions. A comma-delimited list of sets of expressions can contain any number of sets, but each set can contain no more than 1000 expressionsUse here oracle tuple( A comma-delimited list of sets of expressions) That is, tuples , The grammar is as follows :
SELECT * FROM TABLE_NAME WHERE (1, COLUMN_NAME) IN
((1, VALUE_1),
(1, VALUE_2),
...
...
...
...
(1, VALUE_1000),
(1, VALUE_1001));
For example, we want to go through users from the user list id Query user information can be written as follows :
select * from user u where (1, u.id) in ((1, 'id001'),(1,'id002'),(1,'id003'))
The above statement is actually equivalent to :
select * from user u where (1=1 and u.id='id001') or (1=1 and u.id='id002') or (1=1 and u.id='id003')
Most of your projects will use ORM The frame is like MyBatis We can use MyBatis Of foreach It was written here :
where u.id in
<foreach collection="userIds" item="item" separator="," open="(" close=")" index="">
#{item}
</foreach>
Now change to :
where (1, u.id) in
<foreach collection="userIds" item="item" separator="," open="(" close=")" index="">
(1, #{item})
</foreach>
3、 ... and 、 summary
If it helps you , Please point a favor or collect it ! Your attention is my biggest motivation .边栏推荐
- Framework step by step easy-to-use process
- How Visio can quickly generate the same pattern and image matrix
- Openjudge: patient queuing
- JVM notes 3: class loading and bytecode Technology
- Deep learning medical image model reproduction
- mysql 为查询结果增加序号
- IDEA配置 service(Run Dashboard) 服务,多模块同时启动
- repackag failed: Unable to find main class
- 框架一步一步方便使用的流程
- 深度学习医学图像模型复现
猜你喜欢

Multi module packaging: package: XXX does not exist

visio如何快速生成相同的图案,生成图像矩阵

Writing methods of scientific research papers: add analysis and discussion in the method part to explain their contributions and differences

Personal summary of restful interface use

Fusiongan code learning (I)

Example of main diagram of paper model

多线程进阶:synchronized底层原理,锁优化、锁升级的过程

冶金物理化学复习 --- 复杂反应的速率方程

CentOS7安装MySQL5.7

自定义Json返回数据
随机推荐
冶金物理化学复习 --- 液 - 液相反应动力学
Image enhancement - msrcr
LocalDateTime去掉T,JSONField失效
JVM note 4: Memory Model
openjudge:找出全部子串位置
Mabtis(一)框架的基本使用
The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem
mysql中使用list作为参数进行查询
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
FusionGAN代码学习(一)
使用navicat或plsql导出csv格式,超过15位数字后面变成000(E+19)的问题
JVM篇 笔记3:类加载与字节码技术
restFul接口使用个人总结
oracle查看锁表语句、解锁方法
openjudge:统计数字字符个数
Advanced multithreading: Lock strategy
冶金物理化学复习 --- 金属的电沉积,还原过程
Oracle用sql查询某张表的字段信息(字段类型、长度等)
Pytorch uses hook to get feature map
repackag failed: Unable to find main class