选择显示字体大小

oracle sql性能优化系列(八)

16.       通过内部函数提高sql效率.
     select h.empno,e.ename,h.hist_type,t.type_desc,count(*)

     from history_type t,emp e,emp_history h

     where h.empno = e.empno

and h.hist_type = t.hist_type

group by h.empno,e.ename,h.hist_type,t.type_desc;


通过调用下面的函数可以提高效率.


function lookup_hist_type(typ in number) return varchar2

as

    tdesc varchar2(30);

    cursor c1 is 

        select type_desc

        from history_type

        where hist_type = typ;

begin

    open c1;

    fetch c1 into tdesc;

    close c1;

    return (nvl(tdesc,’?’));

end;

function lookup_emp(emp in number) return varchar2


as
    ename varchar2(30);

    cursor c1 is 

        select ename

        from emp

        where empno=emp;

begin

    open c1;

    fetch c1 into ename;

    close c1;

    return (nvl(ename,’?’));

end;


select h.empno,lookup_emp(h.empno),


h.hist_type,lookup_hist_type(h.hist_type),count(*)


from emp_history h

group by h.empno , h.hist_type;

(译者按: 经常在论坛中看到如 ’能不能用一个sql写出….’ 的贴子, 殊不知复杂的sql往往牺牲了执行效率. 能够掌握上面的运用函数解决问题的方法在实际工作中是非常有意义的)


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons