系统环境:
1、操作系统:Windows 2000 Server
2、数据库:Oracle 8i R2 (8.1.6) for NT 企业版
3、安装路径:C:ORACLE
ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi[8.22MB]
http://activestate.com/download/ActivePerl/Windows/5.6/ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi
安装方法:
一、安装 Perl 解释器
第一步,双击 ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi 文件进行安装,使用缺省配置进行安装
安装目录选择c:perl;
第二步,修改注册表,运行 RegEdit
1、定位->HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesW3SVCParametersScript Map
2、新建字符串:名称:".pl" <——>数据:"c:perlbinperl.exe %s %s"
3、新建字符串:名称:".cgi"<——>数据:"c:perlbinperl.exe %s %s"
第三步,设置 IIS 服务器
开始->设置->控制面板->管理工具->Internet 服务管理器->默认Web站点->
鼠标右键->属性->主目录->配置->添加->
可执行文件(X):“C:PerlbinPerl.exe %s %s”->扩展名(E):“.pl”->
确定->确定->确定->
默认Web站点->鼠标右键->新建->虚拟目录->下一步->别名(perl)->
目录选择(c:perl)->添加读取、运行脚本、执行权限->下一步->完成->
注:ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi安装完,才能使用ppm命令
注:Perl通过DBI/DBD客户接口提供对DB2、Oracle、Sybase、Informix、Mysql...等数据库的访问
二、安装 Perl 连接数据库的模块,先安DBI,后安Oracle接口模块
首先,拨号或通过专线连接到Internet上
C:>ppm
PPM interactive shell (2.1.1) - type 'help' for available commands.
PPM>
PPM> install dbi
Install package 'dbi?' (y/N): y
Retrieving package 'dbi'...
Installing C:PerlsitelibautoDBIdbd_xsh.h
Installing C:PerlsitelibautoDBIDBI.bs
Installing C:PerlsitelibautoDBIDBI.dll
Installing C:PerlsitelibautoDBIDBI.exp
Installing C:PerlsitelibautoDBIDBI.lib
Installing C:PerlsitelibautoDBIdbipport.h
Installing C:PerlsitelibautoDBIDBIXS.h
Installing C:PerlsitelibautoDBIdbi_sql.h
Installing C:PerlsitelibautoDBIDriver.xst
Installing C:PerlsitelibDBI.pm
Installing C:PerlsitelibWin32DBIODBC.pm
Installing C:PerlsitelibDBIDBD.pm
Installing C:PerlsitelibDBIFAQ.pm
Installing C:PerlsitelibDBIFormat.pm
Installing C:PerlsitelibDBIProxyServer.pm
Installing C:PerlsitelibDBIShell.pm
Installing C:PerlsitelibDBIW32ODBC.pm
Installing C:PerlsitelibDBDADO.pm
Installing C:PerlsitelibDBDExampleP.pm
Installing C:PerlsitelibDBDMultiplex.pm
Installing C:PerlsitelibDBDNullP.pm
Installing C:PerlsitelibDBDProxy.pm
Installing C:PerlsitelibDBDSponge.pm
Installing C:PerlsitelibBundleDBI.pm
Installing C:Perlbindbiproxy
Installing C:Perlbindbiproxy.bat
Installing C:Perlbindbish
Installing C:Perlbindbish.bat
Writing C:PerlsitelibautoDBI.packlist
PPM>
PPM> install dbd-oracle
Install package 'dbd-oracle?' (y/N): y
Retrieving package 'dbd-oracle'...
Installing C:PerlsitelibautoDBDOracleOracle.bs
Installing C:PerlsitelibautoDBDOracleOracle.dll
Installing C:PerlsitelibautoDBDOracleOracle.exp
Installing C:PerlsitelibautoDBDOracleOracle.lib
Installing C:Perlsiteliboraperl.ph
Installing C:PerlsitelibOraperl.pm
Installing C:PerlsitelibDBDOracle.pm
Installing C:Perlbinora_explain
Installing C:Perlbinora_explain.bat
Writing C:PerlsitelibautoDBDOracle.packlist
PPM>
PPM> install dbd-oracle8
Install package 'dbd-oracle8?' (y/N): y
Retrieving package 'dbd-oracle8'...
Installing C:PerlsitelibautoDBDOracleOracle.dll
Installing C:PerlsitelibautoDBDOracleOracle.exp
Installing C:PerlsitelibautoDBDOracleOracle.lib
Installing C:Perlsiteliboraperl.ph
Installing C:PerlsitelibOraperl.pm
Installing C:PerlsitelibDBDOracle.pm
Writing C:PerlsitelibautoDBDOracle8.packlist
PPM>
PPM> exit
Quit!
C:>
如果在家中不能上网,可以到Activestate下载各种模块,
网址是:http://www.activestate.com/PPMPackages/
PPM命令的解释
E:>ppm
PPM interactive shell (2.1.1) - type 'help' for available commands.
PPM> help
Commands:
exit - leave the program.
help [command] - prints this screen, or help on 'command'.
install PACKAGES - installs specified PACKAGES.
quit - leave the program.
query [options] - query information about installed packages.
remove PACKAGES - removes the specified PACKAGES from the system.
search [options] - search information about available packages.
set [options] - set/display current options.
verify [options] - verifies current install is up to date.
version - displays PPM version number
exit--退出PPM程序
help--显示PPM帮助
install PACKAGES--安装模块,PACKAGES为模块名
quit--同exit,退出PPM程序
query [options] --查询当前已安装模块,不加参数:查询所有已安装模块
remove PACKAGES --卸载已安装模块
search [options]--查询可供安装的模块,在ActivePerl的站点上
set [options] --
verify [options]--
version --显示PPM版本号
三、第一个Perl例子
给这个程序取名为test.pl,放到c:perl目录下
浏览器中输入http://oradb/perl/test.pl
#-------------------------------------
#!/perl/bin/perl
print "Content-type:text/htmlnn";
print "hellp Perl!";
exit;
#-------------------------------------
四、写第一个连接Oracle的Perl程序test.pl
1、连入SQL*Plus
以system/manager用户登录,
SQL> conn system/manager
创建新的用户:如user1/pass1,赋予connect,resource权限。
SQL> grant connect,resource to user1 identified by pass1;
SQL> conn user1/pass1
SQL> create table test(a varchar2(20),b date);
SQL> insert into test values('原有值',sysdate);
SQL> insert into test values('原有值',sysdate);
SQL> insert into test values('原有值',sysdate);
SQL> commit;
SQL> select a,to_char(b,'yyyy-mm-dd hh24:mi:ss') 日期 from test;
A 日期
-------------------- -------------------
原有值 2000-11-26 00:04:47
原有值 2000-11-26 00:04:47
原有值 2000-11-26 00:04:48
2、在c:perl下创建test.pl,用notebook编辑,输入以下代码
#-------------------------------------
#!/perl/bin/perl
print "Content-type:text/htmlnn";
#引用格式:“use 模块名”
use DBI;
my $dbh = DBI->connect("dbi:Oracle:oradb", 'user1','pass1');
my $sql = qq{ insert into test values('网页生成值',sysdate)};
my $sth = $dbh->prepare( $sq