首页 > 数据库 > Oracle > 关于评审开发人员的sql语句
create unique index temp_c_rate_1ux on temp_c_rate_fix_expr_date (rc_rate_seq_no,service_receiver_id) nologging ;
update ( select rc.last_cyc_expr_date OLD, tmp.shoudate NEW, rc.dl_update_stamp DL
from c_rates rc, temp_c_rate_fix_expr_date tmp
where tmp.rc_rate_seq_no = rc.rc_rate_seq_no and tmp.service_receiver_id = rc.service_receiver_id)
set OLD = NEW,
DL = :patch_id ;
COMMIT ;
drop table temp_c_rate_fix_expr_date;
commit;
这个思路我不反对,其实也是蛮高效的,而且易于控制。
但是细细查看脚本,还是发现了一些问题
首先是关于null的部分,开发人员不是很理解null的用途,其实expiration_date != null这种语句是错误的,需要纠正一下。
create table temp_c_rate_fix_expr_date as
select rc_rate_seq_no,expiration_date,last_cyc_expr_date,(SELECT End_Date FROM Cycle_Control WHERE Cycle_Control.Cycle_Code=c_rates.Cycle_Code AND Trunc(expiration_date,'dd') BETWEEN Start_Date AND End_Date) shoudate,
service_receiver_id
FROM C_RATES WHERE sys_creation_date = to_date('20140818','yyyymmdd') and (expiration_date is not null or expiration_date != null)
and (last_cyc_expr_date = null or last_cyc_expr_date is null);
还有因为这个表是一个临时表,所以只限于这个补丁部署中使用,可以采用nologging模式,性能要高很多。
因为表比较大,所以可以考虑加入并行。
所以这个部分的改进如下:
alter session force parallel ddl parallel 8;
create table temp_c_rate_fix_expr_date nologging as
select rc_rate_seq_no,expiration_date,last_cyc_expr_date,(SELECT End_Date FROM Cycle_Control WHERE Cycle_Control.Cycle_Code=c_rates.Cycle_Code AND Trunc(expiration_date,'dd') BETWEEN Start_Date AND End_Date) shoudate,
service_receiver_id
FROM C_RATES WHERE sys_creation_date = to_date('20140818','yyyymmdd') and (expiration_date is not null )
and (last_cyc_expr_date is null );
update的部分其实也可以好好斟酌一下。如果根据第一步创建的临时表,表中数据很少的时候,是可以考虑不用创建索引的。如果数据量大可以考虑创建索引。
最后一部分是删除临时表,可能开发对这个存在一定的误解。在drop 完成之后又使用了commit,这个是不必要的。
drop table temp_c_rate_fix_expr_date;
commit;
可能看似很细小的错误,也可能引起很严重的问题。如果能在脚本上把把关,最后一道防线就是安全的。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8494287/viewspace-1347009/ ,如需转载,请注明出处,否则将追究法律责任。