📄 1756.html
字号:
end stored_sample;<br>
/<br>
create or replace package body stored_sample as<br>
function get_annual_salary (emp_number in number) return number<br>
is<br>
annual_salary number;<br>
monthly_salary number;<br>
begin<br>
select sal into monthly_salary from emp where empno = emp_number;<br>
annual_salary := monthly_salary * 24;<br>
return (annual_salary);<br>
end get_annual_salary;<br>
end stored_sample;<br>
/<br>
<br>
<br>
上面的程序3是存储进程的一个小示范,它接受一个员工号,返回该员<br>
工的年薪。相关的函数<br>
get_annual_salary封装在PL/SQL包sample_package中。<br>
<br>
如果把程序3拷贝到文件sample.sql,您可以通过sqlplus运行它,如下<br>
所示:<br>
<br>
[oracle@sforza demo]$ sqlplus<br>
<br>
SQL*Plus: Release 8.0.5.0.0 - Production on Sun Mar 7 13:36:32<br>
1999<br>
<br>
(c) Copyright 1998 Oracle Corporation. All rights reserved.<br>
<br>
Enter user-name: scott<br>
Enter password:<br>
<br>
Connected to:<br>
Oracle8 Release 8.0.5.0.0 - Production<br>
PL/SQL Release 8.0.5.0.0 - Production<br>
<br>
SQL> @sample<br>
Package created.<br>
<br>
Package body created.<br>
<br>
SQL> set serveroutput on<br>
SQL> exec<br>
dbms_output.put_line(stored_sample.get_annual_salary(7782))<br>
58800<br>
<br>
PL/SQL procedure successfully completed.<br>
<br>
SQL><br>
<br>
通过其他的编程接口,也可以使用这个PL/SQL包。Python/DCOracle中,<br>
参见Connection对象的procedures成员<br>
JDBC中,参见java.sql.CallableStatement。<br>
<br>
Oracle有众多的内置函数。事实上,大多数您以前用外部代码完成的<br>
功能都可以通过PL/SQL高效地完成。如果您需要什么比较通常的功能,<br>
请参考PL/SQL手册,看您需要的函数是否已经实现了。如果您准备做<br>
大量的Oracle编程的话,经常翻阅PL/SQL手册以熟悉各种函数是大有<br>
好处的。<br>
<br>
管理Oracle for Linux<br>
<br>
如果您已经习惯运行相对不那么复杂的数据库,那么在Oracle中完成<br>
一些日常操作,例如建立新数据库或者性能调谐会显得相当复杂。有<br>
一些关键的配置文件需要维护,如init.ora, config.ora和<br>
tnsnames.ora。<br>
一般有好几种办法指定一些关键参数,如当前的SID。可以在上述的<br>
文件中声明,也可以在环境变量中声明,或者是通过oracle工具的运<br>
行参数。这种灵活性是值得赞赏的,可惜有时搞清那一种设置优先也<br>
很伤脑筋。<br>
<br>
同Linux一样,Oracle提供的安全机制如果管理不当,就形同虚设。<br>
花时间熟悉各种访问规则和设置,以及各种特殊Oracle用户帐号的角<br>
色,还是值得的。<br>
<br>
Oracle的性能调谐是一个非常大,也非常专的话题。调谐得当,可以<br>
很大程度地提高性能。Oracle运行和CPU、内存、外存的关系是相当<br>
复杂的,这些因素必须考虑。另外,PL/SQL包,存储过程,临时表空<br>
间,表结构本身,所有这些都会随着使用而日趋复杂,保证数据库的<br>
结构优化,没有垃圾,绝对比定期从cron运行vacuum复杂得多。<br>
<br>
Oracle DBA(database adminstrator,数据库管理员)是电脑专业人<br>
员中一个著名的亚文化。这并不奇怪。Oracle的强大功能和灵活性,<br>
也同时意味着多得让人发疯的各种小秘密、小技巧、小陷阱,这方面<br>
的特点它绝不比任何人少--包括Linux在内。您在征服Linux时可能<br>
已经发现,O'Reilly的动物园(译注:所有O'Reilly and Associate<br>
出版的书都以动物作封面)是一个很好的去处。如果您需要在Oracle<br>
上完成许多工作,找找黄封面的O'Reilly Oracle专辑。那里,你会<br>
找到比Oracle拜占庭迷宫式文档好的多的信息来源。<br>
<br>
Oracle for Linux vs. Oracle for NT<br>
<br>
NT上的Oracle (译注:Oracle在NT上的销量超过了SQL SERVER,是NT<br>
第一大数据库)为许多管理功能提供了图形界面,类似的功能在UNIX<br>
/Linux上只能通过sqlplus访问。这样的图形界面,设计得与NT控制<br>
面板的其他部分颇为相似。Linux DBA必须熟悉sqlplus。NT的问题是,<br>
许多管理任务要求用户在主控台(机器屏幕前)完成,如果想远程管<br>
理就需要昂贵的第三方软件(或者Oracle Enterprise Manager?)。<br>
UNIX上的Oracle管理可以从任何经过授权的远地进行,效果同在机器<br>
主控台一样。<br>
<br>
NT上的Oracle使用一个进程内的多个进程,而UNIX/Linux上的Oracle<br>
使用多个独立的,使用相互独立的内存空间(译注:UNIX上也有多线<br>
程的部分:Multithreaded Server,MTS,相当于前文提到的listener<br>
的多线程版本。)NT上的实现方式避免了进程间通信,有小小的性能<br>
优势,但UNIX上的实现方式提供了高得多的可靠性和数据完整性,因<br>
为一个Oracle进程不可能污染另一个Oracle进程的地址空间。(译注:<br>
在NT和VMS上,创建一个新的进程比创建一个新的线程昂贵得多,而且<br>
NT的进程间切换很慢,因此微软建议程序员只要有可能就使用多线程。<br>
在UNIX上,建立新进程是比较高效的。而在Linux上,建立新进程和新<br>
的内核线程,kernel thread都使用同一个基本系统调用,效率相当高。)<br>
<br>
在32位的硬件系统上,Linux的ext2文件系统的限制是最大文件为2G,<br>
NT为4G。这并不太影响Oracle的用户,因为表空间tablespace可以扩<br>
展到多个文件上,但还是有小小的效率问题。当然,64位的Linux<br>
(Alpha,Ultra-Sparc, PA-RISC)会消除这些限制,64位的Solaris<br>
(Solaris 7)也一样。(译注:这里其实有一些问题,待我查明再向<br>
各位看官交代)。<br>
<br>
<br>
一些好工具/结束语<br>
<br>
Oracle同时发布了Oracle Application Server (OAS)的Linux版本。<br>
对OAS的深入探讨在本文范围之外,但它确实是连接后端Oracle数据<br>
库,建立Internet或Intranet应用的一个强有力的工具。OAS提供<br>
JAVA开发能力,可以将HTTP和IIOP与OCI网络接口串在一起,具备<br>
友好的界面以便设计WEB表单和报表,还有其他方便的工具。<br>
<br>
Oracle如此流行,自然也有相应的一批开源软件(Open Source)<br>
工具。其中的OWS killer 是一个基于JAVAServlet的可以替代OAS<br>
的WEB接口工具,与Apache WEB服务器、Apache的Jserv JAVA Servelet<br>
模块集成,提供对Oracle数据库的访问。(译注:OWS, Oracle Web<br>
Server是Oracle Application Server早期版本的名称)。<br>
您可以在Matt's House 找到更多的工具以管理Oracle的存储过程、<br>
提供快速的报表功能。<br>
<br>
掌握Oracle可不是举手之劳的事,但也没有必要望而却步。确实,<br>
世上有许多更容易管理的数据库,但如果您需要高级的SQL,或者<br>
PL/SQL的功能,或者trigger,或者各种扩展,或者先进的交易管<br>
理,或者必须和Oracle系统共存,您会发现Linux是一个极佳的<br>
Oracle平台。您已经在Linux的世界中探索了这样远,一定也能应<br>
付Oracle的挑战。<br>
<br>
<br>
资源链接:<br>
<br>
Oracle for Linux正式发布的新闻稿:<br>
http://www.oracle.com/cgi-bin/press/printpr.cgi?<br>
file=199810090500.17129.html&mode=corp&td=01&product=00&<br>
tm=10&fd=01&fm=08&status=Search&ty=1998&limit=100&fy=1998<br>
<br>
在Redhat上安装Oracle 8.0.5和OAS 3的详细指导:<br>
(Step-by-step install notes for Oracle 8.0.5 and Application<br>
Server on Red Hat):<br>
http://jordan.fortwayne.com/oracle<br>
<br>
下载Oracle 8和Oracle Application Server:<br>
http://technet.oracle.com/tech/linux/section.htm<br>
<br>
Oliver Andrich's Python & Linux Page:<br>
http://andrich.net/python<br>
<br>
Oracle on Linux -- Oracle Technet上的论坛<br>
http://f2.dejanews.com/oracletechnet/nonmembers/index.cgi?<br>
do=listmsgs&conf=Early.Linux<br>
<br>
Blackdown.org -- Linux JDK:<br>
http://www.blackdown.org/<br>
<br>
Pythond的Oracle模块:<br>
http://www.zope.org/Download/DCOracle/<br>
<br>
Oracle SQLJ -- 在Java中嵌入SQL:<br>
http://www.oracle.com/java/sqlj/index.html<br>
<br>
OWS Killer:<br>
http://www.adela.sk/kuzela/OWSKiller/<br>
<br>
Matt's House:<br>
http://www.mattshouse.com/procedit/<br>
<br>
在FreeBSD上运行Oracle for Linux<br>
http://www.freebsd.org.ru/linux-oracle.HOW-TO.html<br>
<br>
结束<br>
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -