Oracle专家高级编程学习笔记
文章作者 100test 发表时间 2007:12:15 12:21:19
来源 100Test.Com百考试题网
Expert one-on-one oracle是Oracle专家Thomas Kyte的大作,洋洋大观,总共有1329页,啃起来颇费力气.故作此笔记,记录精华所在.
一.准备工作
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
0select 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>alter system flush shared_pool.
system@webdb>set timing 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
0select 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
0select 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.
/
Oracle封锁策略
Oracle体系结构的3个主要组件:
1.文件:组成数据库实例的5个文件(参数文件,控制文件,数据文件,临时数据文件,重做日志文件)
2.系统全局区域SGA( System Global Area): Java池,共享池等
3.物理进程与线程: 在数据库上运行3种不同类型的进程(服务器server进程,后台backgroud进程,从属slave进程)