一.准备工作
1.建立基本调试环境
Create demo schema(建立演示模式)
sqlplus>start $ORACLE_HOME/sqlplus/demo/demobld.sql
2.建立login.sql
以下是引用片段:
define_editor=vi
set serveroutput on size 1000000
set trimspool on
set long 500
set linesize 100
set pagesize 9999
column plan_plus_exp format a80
column global_name new_value gname
select lower(user)||'@'||decode(global_name,'WEBDB.FANYAMIN.NET','webdb',global_name) global_name from global_name;
set sqlprompt '&gname>'
set termout on
3.在sqlplus中配置AutoTrace
1)cd $ORACLE_HOME/rdbms/admin
log into sqlplus as system(connect system/manager@webdb)
run @utlxplan
run create public synonym plan_table for plan_table;
run grant all on plan_table to public;
2)
cd $ORACLE_HOME/sqlplus/admin
log into sqlplus as sys(connect sys/change_on_install@webdb)
run @plustrce
run grant plustrace to public;
二.内容
1.开发成功的
Oracle应用程序
一条简单秘诀
if(possible) 就用单条
SQL语句完成
else if(possible) 用plsql程序
else if(possible) 用java存储过程
else if(possible) 用C外部过程
else 考虑是否真有必要这样做
两个指导方针
1)不要在MTS下运行长事务<45s
2)使用绑定变量
system@webdb>altersystem flush shared_pool;
system@webdb>settiming on
执行这两个sql文件,一比较,发现使用绑定变量后,速度快多了
以下是引用片段:
--bindtest1.sql, did not use bind variable
declare
type rc is ref cursor;
l_rc rc;
l_dummy all_objects.object_name%type;
l_start number default dbms_utility.get_time;
begin
for i in 1..1000
loop
open l_rc for
'select object_name from all_objects where object_id='||i;
fetch l_rc into l_dummy;
close l_rc;
end loop;
dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)||'seconds...');
end;
/
--bindtest2.sql, use bind variable
declare
type rc is ref cursor;
l_rc rc;
l_dummy all_objects.object_name%type;
l_start number default dbms_utility.get_time;
begin
for i in 1..1000
loop
open l_rc for
'select object_name from all_objects where object_id=:x'
using i;
fetch l_rc into l_dummy;
close l_rc;
end loop;
dbms_output.put_line(round((dbms_utility.get_time-l_start)/100,2)||'seconds...');
end;
/