perl操作oracle資料庫

2021-08-26 06:07:12 字數 2881 閱讀 6267

到:

和到:# tar zxvf dbi-1.613.tar.gz

# cd dbi-1.613

# perl makefile.pl

#make

#make install

#cd

# tar zxvf dbd-oracle-1.21.tar.gz

# cd dbd-oracle-1.21

在oracle的home目錄下的.bash_profile最後加上export ld_library_path=$oracle_home/lib:$oracle_home/jdbc/lib:$ld_library_path

# . /home/db/oracle/.bash_profile

# perl makefile.pl

#make

#make install

若報如下錯誤:

nstall_driver(oracle) failed: can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/dbd/oracle/oracle.so' for mod

ule dbd::oracle:

解決方案如下:

# echo /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/dbd/oracle >> /etc/ld.so.conf

# ldconfig

# ldd /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/dbd/oracle/oracle.so

檢視lib包的相關性是否正常

我的測試資料如下:

建表與插入資料

create table books

(isbn varchar2(13) not null,

title varchar2(200),

summary varchar2(2000),

author varchar2(200),

date_published date,

page_count number

);insert into books (isbn, title, summary, author, date_published, page_count)

values ('0-596-00977-1', 'oracle pl/sql programming', 'for the past ten years, oracle pl/sql programming has been the bestselling book on pl/sql', 'steven feuerstein', to_date('01-09-2010 17:45:07', 'dd-mm-yyyy hh24:mi:ss'), 700);

insert into books (isbn, title, summary, author, date_published, page_count)

values ('0-13-238182-6', 'perl by example', 'perl by example, fourth edition, is the easiest, most hands-on way to learn perl.', 'ellie quigley', to_date('01-09-2010 18:29:56', 'dd-mm-yyyy hh24:mi:ss'), 600);

commit;

使用到的函式:

create or replace function booktitle (isbn_in in varchar2)

return varchar2

isl_isbn books.title%type;

cursor icur is select title from books where isbn = isbn_in;

begin

open icur;

fetch icur into l_isbn;

close icur;

return l_isbn;

end;

/callbook.pl的 perl指令碼如下:

#!/usr/bin/perl

use strict;

use dbi qw(:sql_types);

# either make the connection or die

my $dbh = dbi->connect(

'dbi:oracle:db',

'scott',

'tiger',

) || die "database connection not made: $dbi::errstr";

my $retval;

# make parse call to oracle, get statement handle

eval );

# bind the parameters and execute

$func->bind_param(":bind1", "0-13-238182-6");

$func->bind_param_inout(":retval", \$retval, sql_varchar);

$func->execute;

};if( $@ ) else

# don't forget to disconnect

$dbh->disconnect;

其中:

'dbi:oracle:db',

'scott',

'tiger',

的db為資料庫sid,scott和tiger為使用者名稱和密碼

啟動資料庫和***後,在oracle使用者下執行perl指令碼:

$perl callbook.pl

oracle資料庫操作

1 oracle安裝目錄,配置目錄 通過環境變數查詢 set grep oracle 網路配置在 oracle home network admin tnsnames.ora 2 oracle資料庫 select from v database 3 oracle表 4 oracle 工具 linux...

Oracle資料庫操作。

物件導向告一段落,重新撿起來sql server的知識,幸好資料庫語言都差不多,讓我重新學習oracle的時候並沒有想象中的費勁,只需要複習起來舊知識,再融合oracle特有的語法就足矣。廢話不多說,進入正題,此文章按照網上的資料 個人理解編寫,盡量做到通俗易懂,以便日後忘了能夠見文知意。注 sql...

oracle資料庫操作

1 建表空間 create tablespace ccpbs datafile home oracle bossdata ora data ccpbs index01.dbf size 100m reuse default storage initial 5000k next 5000k pctin...