- 系統(tǒng)環(huán)境:
1、操作系統(tǒng):Windows 2000 Server 2、數(shù)據(jù)庫: Oracle 8i R2 (8.1.6) for NT 企業(yè)版 3、安裝路徑:C:\ORACLE
- 安裝方法:
一、安裝 Perl 解釋器第一步,雙擊 ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi 文件進(jìn)行安裝,使用缺省配置進(jìn)行安裝 安裝目錄選擇c:\perl; 第二步,修改注冊表,運行 RegEdit 1、定位->HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Script Map 2、新建字符串:名稱:".pl" <——>數(shù)據(jù):"c:\perl\bin\perl.exe %s %s" 3、新建字符串:名稱:".cgi"<——>數(shù)據(jù):"c:\perl\bin\perl.exe %s %s" 第三步,設(shè)置 IIS 服務(wù)器 開始->設(shè)置->控制面板->管理工具->Internet 服務(wù)管理器->默認(rèn)Web站點-> 鼠標(biāo)右鍵->屬性->主目錄->配置->添加-> 可執(zhí)行文件(X):“C:\Perl\bin\Perl.exe %s %s”->擴(kuò)展名(E):“.pl”-> 確定->確定->確定-> 默認(rèn)Web站點->鼠標(biāo)右鍵->新建->虛擬目錄->下一步->別名(perl)-> 目錄選擇(c:\perl\)->添加讀取、運行腳本、執(zhí)行權(quán)限->下一步->完成-> 注:ActivePerl-5.6.0.620-MSWin32-x86-multi-thread.msi安裝完,才能使用ppm命令注:Perl通過DBI/DBD客戶接口提供對DB2、Oracle、Sybase、Informix、Mysql...等數(shù)據(jù)庫的訪問二、安裝 Perl 連接數(shù)據(jù)庫的模塊,先安DBI,后安Oracle接口模塊首先,撥號或通過專線連接到Internet上C:\>ppmPPM interactive shell (2.1.1) - type ‘help‘ for available commands.PPM>PPM> install dbiInstall package ‘dbi?‘ (y/N): yRetrieving package ‘dbi‘...Installing C:\Perl\site\lib\auto\DBI\dbd_xsh.hInstalling C:\Perl\site\lib\auto\DBI\DBI.bsInstalling C:\Perl\site\lib\auto\DBI\DBI.dllInstalling C:\Perl\site\lib\auto\DBI\DBI.expInstalling C:\Perl\site\lib\auto\DBI\DBI.libInstalling C:\Perl\site\lib\auto\DBI\dbipport.hInstalling C:\Perl\site\lib\auto\DBI\DBIXS.hInstalling C:\Perl\site\lib\auto\DBI\dbi_sql.hInstalling C:\Perl\site\lib\auto\DBI\Driver.xstInstalling C:\Perl\site\lib\DBI.pmInstalling C:\Perl\site\lib\Win32\DBIODBC.pmInstalling C:\Perl\site\lib\DBI\DBD.pmInstalling C:\Perl\site\lib\DBI\FAQ.pmInstalling C:\Perl\site\lib\DBI\Format.pmInstalling C:\Perl\site\lib\DBI\ProxyServer.pmInstalling C:\Perl\site\lib\DBI\Shell.pmInstalling C:\Perl\site\lib\DBI\W32ODBC.pmInstalling C:\Perl\site\lib\DBD\ADO.pmInstalling C:\Perl\site\lib\DBD\ExampleP.pmInstalling C:\Perl\site\lib\DBD\Multiplex.pmInstalling C:\Perl\site\lib\DBD\NullP.pmInstalling C:\Perl\site\lib\DBD\Proxy.pmInstalling C:\Perl\site\lib\DBD\Sponge.pmInstalling C:\Perl\site\lib\Bundle\DBI.pmInstalling C:\Perl\bin\dbiproxyInstalling C:\Perl\bin\dbiproxy.batInstalling C:\Perl\bin\dbishInstalling C:\Perl\bin\dbish.batWriting C:\Perl\site\lib\auto\DBI\.packlistPPM>PPM> install dbd-oracleInstall package ‘dbd-oracle?‘ (y/N): yRetrieving package ‘dbd-oracle‘...Installing C:\Perl\site\lib\auto\DBD\Oracle\Oracle.bsInstalling C:\Perl\site\lib\auto\DBD\Oracle\Oracle.dllInstalling C:\Perl\site\lib\auto\DBD\Oracle\Oracle.expInstalling C:\Perl\site\lib\auto\DBD\Oracle\Oracle.libInstalling C:\Perl\site\lib\oraperl.phInstalling C:\Perl\site\lib\Oraperl.pmInstalling C:\Perl\site\lib\DBD\Oracle.pmInstalling C:\Perl\bin\ora_explainInstalling C:\Perl\bin\ora_explain.batWriting C:\Perl\site\lib\auto\DBD\Oracle\.packlistPPM> PPM> install dbd-oracle8Install package ‘dbd-oracle8?‘ (y/N): yRetrieving package ‘dbd-oracle8‘...Installing C:\Perl\site\lib\auto\DBD\Oracle\Oracle.dllInstalling C:\Perl\site\lib\auto\DBD\Oracle\Oracle.expInstalling C:\Perl\site\lib\auto\DBD\Oracle\Oracle.libInstalling C:\Perl\site\lib\oraperl.phInstalling C:\Perl\site\lib\Oraperl.pmInstalling C:\Perl\site\lib\DBD\Oracle.pmWriting C:\Perl\site\lib\auto\DBD\Oracle8\.packlistPPM> PPM> exitQuit!C:\>如果在家中不能上網(wǎng),可以到Activestate下載各種模塊,網(wǎng)址是:http://www.activestate.com/PPMPackages/PPM命令的解釋E:\>ppmPPM interactive shell (2.1.1) - type ‘help‘ for available commands.PPM> helpCommands: 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 numberexit --退出PPM程序help --顯示PPM幫助install PACKAGES --安裝模塊,PACKAGES為模塊名quit --同exit,退出PPM程序query [options] --查詢當(dāng)前已安裝模塊,不加參數(shù):查詢所有已安裝模塊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/html\n\n"; print "hellp Perl!";exit;#-------------------------------------四、寫第一個連接Oracle的Perl程序test.pl1、連入SQL*Plus以system/manager用戶登錄,SQL> conn system/manager創(chuàng)建新的用戶:如user1/pass1,賦予connect,resource權(quán)限。SQL> grant connect,resource to user1 identified by pass1;SQL> conn user1/pass1SQL> 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:482、在c:\perl下創(chuàng)建test.pl,用notebook編輯,輸入以下代碼#-------------------------------------#!/perl/bin/perlprint "Content-type:text/html\n\n";#引用格式:“use 模塊名”use DBI;my $dbh = DBI->connect("dbi:Oracle:oradb", ‘user1‘,‘pass1‘);my $sql = qq{ insert into test values(‘網(wǎng)頁生成值‘,sysdate)}; my $sth = $dbh->prepare( $sql );$sth->execute(); $dbh->disconnect();print "新記錄已生成,請用SQL*Plus重新查詢!";exit;#-------------------------------------注:dbi:Oracle:oradb中的oradb是Oracle數(shù)據(jù)庫的實例名,使用時,請更換成你自己的實例名3、打開一個瀏覽器窗口,輸入以下地址來查看運行結(jié)果http://oradb/perl/test.pl注:oradb為本機(jī)計算機(jī)名4、進(jìn)入SQL*Plus,重新查詢測試表test,查看新記錄是否生成成功SQL> conn user1/pass1SQL> 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網(wǎng)頁生成值 2000-11-26 00:15:45網(wǎng)頁生成值 2000-11-26 00:15:58網(wǎng)頁生成值 2000-11-26 00:16:15網(wǎng)頁生成值 2000-11-26 00:16:28經(jīng)驗證,新記錄生成成功。
|