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

【idea插件神器】教你如何使用IDEA一键set实体类中所有属性

Personal summary of restful interface use

JUC notes

visio如何精确控制图形的大小和位置及角度

regular expression

蒸馏模型图

ResNet结构对比

VMware Workstation 与 Device/Credential Guard 不兼容。禁用 Device/Credential Guard

架构设计思考之一(SSO设计)

Video twins: the starting point of informatization upgrading of smart Parks
随机推荐
JVM notes 3: class loading and bytecode Technology
ECCV22 最新54篇论文主图整理
Pytorch uses maxpool to realize image expansion and corrosion
IDEA使用dev-tool实现热部署
Digital twin solutions inject new momentum into the construction of chemical parks
Fusiongan code learning (I)
openjudge:统计数字字符个数
Oracle创建表、删除表、修改表(添加字段、修改字段、删除字段)语句总结
There is no crossover in the time period within 24 hours
Review of metallurgical physical chemistry ---- gas solid reaction kinetics
pytorch 计算模型的GFlops和total params的方法
PyTorch 使用 MaxPool 实现图像的膨胀和腐蚀
MySQL uses list as a parameter to query
docker 部署 mysql5.7.35
冶金物理化学复习 --- 液 - 液相反应动力学
List < long >, list < integer > convert each other
Example of main diagram of paper model
Response<T>类
Video twins: the starting point of informatization upgrading of smart Parks
正则表达式