简体   繁体   English

加载数据或更新列 Oracle-sql

[英]Loading data or updating a column Oracle-sql

I have a table with a very large volume (oracle 11g), and I do thousands of updates but this in terms of performance takes hours.我有一个容量很大的表(oracle 11g),我做了数千次更新,但这在性能方面需要几个小时。 Some fields and columns from my table:我表中的一些字段和列:

DEP     EMP FA  LO  DAC
98001   333 123 124 null
98001   333 321 132 null
98001   333 234 233 null

Here is the 1st method (query executed via SQL plus):这是第一种方法(通过 SQL plus 执行的查询):

WHENEVER SQLERROR EXIT SQL.SQLCODE
UPDATE My_table set DAC= '5' where DEP ='98001' AND  EMP ='333' and FA='123' and LO='124'  
UPDATE My_table set DAC= '8' where DEP ='98001' AND  EMP ='333' and FA='321' and LO='132'  
UPDATE My_table set DAC= '9' where DEP ='98001' AND  EMP ='333' and FA='123' and LO='233'  
… around 10 000 lines
Commit ;

2nd method (query executed via SQL plus):第二种方法(通过 SQL plus 执行查询):

UPDATE My_table
SET DAC = ( 
CASE  
when FA='123' and LO='124'  THEN  '5'
when FA='321' and LO='132'  THEN  '8'
when FA='234' and LO='233'  THEN  '9'
… around 10 000 lines
END) where DEP ='98001' AND  EMP ='333'
AND FA IN ('123', '321', '234', …. around 10 000 FA);

Is there a faster way to load sql the field?有没有更快的方法来加载 sql 字段? via loading only the field according to the condition of the where clause?通过根据 where 子句的条件仅加载字段? Or insert my field?还是插入我的字段? … Thanks for your help. … 谢谢你的帮助。

1st method第一种方法

Create one index on multiple columns in your big fat table在你的大胖表中的多列上创建一个索引

create index <index_name> on <table_name> (DEP, EMP, FA, LO);

2nd method第二种方法

While I doubt that it will solve your performance issue, there is a workaround for the max 1000 IN parameters.虽然我怀疑它能否解决您的性能问题,但对于最大 1000 个 IN 参数有一个解决方法。

You can work your way around it by making it a 2 value comparison like this您可以通过像这样进行 2 值比较来解决它

UPDATE My_table
SET    DAC = ...
WHERE  DEP ='98001'
AND    EMP ='333'
AND    ('dummy',FA) IN (('dummy','123'),('dummy', '321'), ('dummy','234'), …. around 10 000 FA);

That way you have a maximum of 100,000 values.这样,您最多可以有 100,000 个值。

Another tip另一个提示

Check the datatype of your DEP, EMP, FA and LO columns, you might be doing VARCHAR2 vs NUMBER comparisons.检查 DEP、EMP、FA 和 LO 列的数据类型,您可能正在进行 VARCHAR2 与 NUMBER 比较。 And though it works, oracle does execute an implicit conversion to be able to do a compare, which can cause performance issues when comparing lots and lots of values.尽管它有效,但 oracle 确实执行了隐式转换以进行比较,这在比较大量值时可能会导致性能问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM