当前位置:网站首页>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 .边栏推荐
猜你喜欢

冶金物理化学复习 --- 气-液相反应动力学

多模块打包:程序包:xxx不存在

框架一步一步方便使用的流程

The difference between get and post

Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade

蒙特卡罗方法求解圆周率π并用turtle画点,以及完成进度条问题

IDEA使用dev-tool实现热部署

ECCV22 最新54篇论文主图整理

regular expression

How Visio accurately controls the size, position and angle of graphics
随机推荐
RESNET structure comparison
sql 查询list时两次的数据不一致,自动加上了limit
Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
多线程进阶:synchronized底层原理,锁优化、锁升级的过程
Redis 之布隆过滤器
Redis' bloom filter
Advanced multithreading: Lock strategy
Deep learning medical image model reproduction
接口幂等性问题
CentOS7安装MySQL5.7
When using \hl for highlighting, latex always reports an error when encountering a reference, showing that there are fewer or more parentheses
Openjudge: perpetual calendar
repackag failed: Unable to find main class
Methods of gflops and total params of pytorch calculation model
JVM note 4: Memory Model
项目中问题合集
Review of metallurgical physical chemistry --- liquid liquid reaction kinetics
docker 部署 mysql5.7.35
pytorch 计算模型的GFlops和total params的方法
多线程进阶:锁的策略