Sql 提高存储过程的性能
我是一个非db的人。。在改进以下sp示例(如使用全局临时表或索引)时,您是否可以分享您的观点,或者您是否可以改进现有的查询。在原始代码中,我将有许多针对不同表的更新查询。谢谢Sql 提高存储过程的性能,sql,stored-procedures,oracle11g,oracle-sqldeveloper,Sql,Stored Procedures,Oracle11g,Oracle Sqldeveloper,我是一个非db的人。。在改进以下sp示例(如使用全局临时表或索引)时,您是否可以分享您的观点,或者您是否可以改进现有的查询。在原始代码中,我将有许多针对不同表的更新查询。谢谢 CREATE OR REPLACE PROCEDURE SYSTEM.process_log1 IS cursor cur_attuid_change is select sup.id as id, sup.name as name, sup.role as role, sup.te
CREATE OR REPLACE PROCEDURE SYSTEM.process_log1
IS
cursor cur_attuid_change is
select
sup.id as id,
sup.name as name,
sup.role as role,
sup.technology as technology
from main hr, secondary sup
where sup.id=hr.id;
BEGIN
-- update records in main tables from the cursor
for rec_attuid_change in cur_attuid_change loop
update main t1
set t1.id = rec_attuid_change.id,
t1.name = rec_attuid_change.name,
t1.ROLE=rec_attuid_change.role,
t1.technology=rec_attuid_change.technology
where t1.id = rec_attuid_change.id;
commit;
update main1 t1
set t1.id = rec_attuid_change.id,
t1.name = rec_attuid_change.name,
t1.ROLE=rec_attuid_change.role,
t1.technology=rec_attuid_change.technology
where t1.id = rec_attuid_change.id;
commit;
update main2 t1
set t1.id = rec_attuid_change.id,
t1.name = rec_attuid_change.name,
t1.ROLE=rec_attuid_change.role,
t1.technology=rec_attuid_change.technology
where t1.id = rec_attuid_change.id;
commit;
end loop;
END;
/试试这个:
CREATE OR REPLACE PROCEDURE SYSTEM.process_log1
BEGIN
update main t1
set (t1.id, t1.name, t1.ROLE, t1.technology ) =
(select
sup.id as id,
sup.name as name,
sup.role as role,
sup.technology as technology
from
main hr,
secondary sup
where
sup.id=hr.id
and sup.Id = t1.Id);
commit;
update main1 t1
set (t1.id, t1.name, t1.ROLE, t1.technology ) =
(select
sup.id as id,
sup.name as name,
sup.role as role,
sup.technology as technology
from
main hr,
secondary sup
where
sup.id=hr.id
and sup.Id = t1.Id);
commit;
update main2 t1
set (t1.id, t1.name, t1.ROLE, t1.technology ) =
(select
sup.id as id,
sup.name as name,
sup.role as role,
sup.technology as technology
from
main hr,
secondary sup
where
sup.id=hr.id
and sup.Id = t1.Id);
commit;
END;
基本思想是去掉游标,让Oracle运行Set操作(例如,在Venn图中设置,而不是在Set something=中设置)。它将比RAT(一次一排)更快地完成这些任务
我不是100%确定语法,但它来自,大约在页面的三分之一处,您有以下内容:
SET(列名称、列名称……)=(子查询4)
将子查询4从数据库检索到的值分配给列名称列表中的列。子查询必须只返回一行,其中包含列出的所有列。子查询返回的列值按顺序分配给列列表中的列。第一个值分配给列表中的第一列,第二个值分配给列表中的第二列,依此类推