当前位置:网站首页>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 .边栏推荐
- Pytorch uses maxpool to realize image expansion and corrosion
- Openjudge: filter extra spaces
- 项目中问题合集
- Openjudge: stone scissors cloth
- Review of metallurgical physical chemistry --- liquid liquid reaction kinetics
- 蒸馏模型图
- ArrayList多线程安全解决办法
- mybaties foreach多选查询,index循环,取消and/or标签
- openjudge:统计数字字符个数
- 多模块打包:程序包:xxx不存在
猜你喜欢

ECCV22 最新54篇论文主图整理

GET与POST区别

BigDecimal 进行四舍五入 四舍六入和保留两位小数

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

FusionGAN代码学习(一)

冶金物理化学复习 --- 冶金反应动力学基础与多相反应动力学特征

BigDecimal rounds and retains two decimal places

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

Long和Integer如何进行比较,为什么报错

RESNET structure comparison
随机推荐
Openjudge: judge whether the string is palindrome
正则表达式
FeignClient 调用GET 方法报错 ResultVO{result=未知异常,异常详情:Request method ‘POST‘ not supported
Mybats foreach multi select query, index loop, and cancel the and/or tag
Fusiongan code learning (I)
多线程进阶:锁的策略
regular expression
Mutual conversion between latex and word
Digital twin solutions inject new momentum into the construction of chemical parks
ByteBuffer.position 抛出异常 IllegalArgumentException
蒸馏模型图
Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics
Mysql处理遗留数据样例
URL form
Image enhancement - msrcr
Openjudge: campus accommodation reservation system
Openjudge: filter extra spaces
Mabtis (I) basic use of framework
BigDecimal 进行四舍五入 四舍六入和保留两位小数
openjudge:过滤多余的空格