【发布时间】:2020-08-18 21:31:36
【问题描述】:
我正在尝试在全局表中插入逗号分隔值。当数据很大时,处理数据需要很长时间。我需要优化我的插入查询,有没有其他方法可以实现下面的插入语句以获得更好的优化?请检查下面的代码以获取更多信息。感谢您提供任何帮助。
//my proc
emp_id in CLOB;
//insert statement
insert into Global_Emp_Tbl
with inputs(str) as(
select to_clob(emp_id)
from dual
),
temp_table(s, n, empid, st_pos, end_pos) as (
select ',' || str || ',', -1, null, null, 1
from inputs
union all
selct s, n+1, substr(s, st_pos, end_pos - st_pos),
end_pos + 1, instr(s, ',', 1, n+3)
from temp_table
where end_pos != 0
)
select empid from temp_table where empid is not null;
commit;
//using insert table in where clause
exists( select 1 from Global_Emp_Tbl gt where e.id =gt.emp_id ) //joining with main table
【问题讨论】:
-
通常避免数据库中的 CSV 数据 - 这使得它更难使用。
-
@AndrewMorton 我该如何避免呢?我必须在 proc 中发送数据来处理/过滤数据
-
@AndrewMorton 我在这里非常有限,我唯一能做的就是创建全局临时表。
-
Global_Emp_Tbl.emp_id的数据类型是什么?是VARCHAR2还是CLOB?
标签: sql oracle stored-procedures