变量的应用在spool时

来源:互联网 发布:淘宝企业号如何注册 编辑:程序博客网 时间:2024/04/30 12:13
spool的sql语句很是复杂,为了减少运行时间提高性能,我考虑了首先根据索引找出符合条件的记录总数,并根据总数是否大于0,来对要运行的sql添加条件。

如:
sql> variable a2 number;
sql> select count(*) into :a2 from table where length(zd)=2;
在要运行sql中,select .... from table where ..... and :a2>0;

当然,我们需要谨慎的罗列条件计算出a2,以便让它最大程度的符合我们的要求。总之一切多为了提高性能。

我具体的实例如下:
--每行的字符数目
set linesize 999
--不产生新页
set pagesize 50000
--列的设置
--col username format a4
--col a format 999,999,999
--输出列标题
set heading on
--禁止显示最后一行的计数反馈信息
set feedback off
--执行命令文件时,命令本身是否显示在屏幕上
set echo off
--
set termout off
--清空多余的空格,如:linesize过长
set trimout on
set trimspool on

--以下业务逻辑
......
--var a2,a3
variable a2 number;
variable a3 number;
BEGIN
select count(*) into :a2 from table where length(ztb)=2;
select count(*) into :a3 from table where length(ztb)=3;
end;
/
spool e:/output/tt_clzt_1.txt;
PROMPT xxx值不在指定的yyy表中;
select .....from .... where .... and :a3>0 ;

spool off;