标签:
Informix学习札记:
启动:oninit
关闭:onmode -k
将数据库public_bak导出到目录/usr/informix/export中:
$ dbexport public_bak -o /usr/informix/export
执行结束后,会在export目录下,生成一个pubic_bak.exp目录。此目录下,有数据库创建对象的语句及数据。
$ pwd
/usr/informix/export
$ ls
public_bak.exp
$ cd public_bak.exp
$ lc
bank_00104.unl issu_00102.unl secu_00136.unl sz_fu00130.unl zls_r00123.unl
b_sec00134.unl mer_b00101.unl secu_00139.unl sz_op00131.unl zls_t00124.unl
card_00103.unl offli00115.unl settl00108.unl sz_se00137.unl zls_t00126.unl
child00107.unl pos_i00105.unl settl00109.unl telle00106.unl zls_w00122.unl
file_00116.unl public_bak.sql settl00110.unl test_00120.unl zls_w00125.unl
file_00117.unl resp_00112.unl settl00111.unl trans00114.unl zls_w00127.unl
file_00118.unl secub00132.unl sysme00140.unl trans00138.unl zls_w00128.unl
file_00119.unl secub00133.unl sysme00141.unl txn_i00113.unl
hist_00100.unl secu_00135.unl sz_cu00129.unl zls_h00121.unl
$
导入数据库:dbimport
将/usr/informix/export目录下的public_sto子目录装入public_sto数据库。假定模式文件为/usr/informix/export/public_sto.exp/public_sto.sql。使用如下命令导入库:
$ dbimport public_sto -c -i /usr/informix/export
这样,对象及数据都导入到数据库中了。
导入数据到数据库中:dbload
$ cat test_c1.sql
FILE test_c1.unl DELIMITER ‘|‘ 2;
INSERT INTO test_c;
$ cat test_c1.unl
13|Tom
14|James
$
将 test_c1.unl中的记录,导入到数据库public_bak的表test_c中:
$ dbload -d public_bak -c test_c1.sql
DBLOAD Load Utility INFORMIX-SQL Version 7.30.UC2
Copyright (C) Informix Software, Inc., 1984-1998
Software Serial Number AAC#J495018
Error logging file name: test_c1
In INSERT statement number 1 of raw data file test_c1.unl.
Row number 3 is bad.
||
Reached unexpected end of line while reading field
Table test_c had 2 row(s) loaded into it.
$
当然,也可以加上参数来指定输出日志:
$ dbload -d public_bak -c test_c1.sql -l test_c1.log
导出数据库对象:dbschema
如果想要输出数据库public_bak中的表test_c的建表语句,可以使用以下语句:
$ dbschema -t test_c -d public_bak -ss test_c2.sql
DBSCHEMA Schema Utility INFORMIX-SQL Version 7.30.UC2
Copyright (C) Informix Software, Inc., 1984-1998
Software Serial Number AAC#J495018
$ vi test_c2.sql
"test_c2.sql" 13 lines, 268 characters
{ TABLE "informix".test_c row size = 24 number of columns = 2 index size = 0 }
create table "informix".test_c
(
id integer
default 0,
name char(20)
) extent size 16 next size 16 lock mode page;
revoke all on "informix".test_c from "public";
导入数据库的对象:dbschema
如:数据库的对象创建文件内容如下:
$ cat test_c2.sql
{ TABLE "informix".test_c row size = 24 number of columns = 2 index size = 0 }
create table "informix".test_c
(
id integer
default 0,
name char(20)
);
revoke all on "informix".test_c from "public";
导入对象的命令如下(public_bak为数据库名,test_c2.sql为创建对象文件):
$ dbaccess public_bak test_c2.sql
Database selected.
Table created.
Permission revoked.
Database closed.
$
导出数据库表中的数据:unload
用isql或dbaccess命令,进入到informix操作数据库操作界面,选择需要导出的表数据。如:导出表test_c中的数据,到文件test_c3.dmp文件中:
unload to ‘test_c3.dmp‘ select * from test_c;
$ cat test_c3.dmp
11|James|
12|David|
13|Tom|
14|James|
15|Standand|
16|Stone|
$
导入表数据:load
执行命令的方式,同unload。如:将test_c3.dmp文件中的数据导入到表test_c中:
load from ‘test_c3.dmp‘ insert into test_c;
查询验证一下:
select * from test_c
id name
11 James
12 David
13 Tom
14 James
15 Standand
16 Stone
新建一个存储过程:
$ vi test_proc.sql
"test_proc.sql" 12 lines, 168 characters
create procedure "informix".test_proc_a()
returning int;
define x int;
let x=16;
insert into test_c values( x, ‘Rolex‘ );
return x;
end procedure;
$ dbaccess public_bak test_proc.sql
Database selected.
Routine created.
Database closed.
$
执行存储过程:先使用命令dbaccess登录到数据库的交互环境。执行:
execute procedure test_proc_a();
执行结果:
(expression)
16
Jesus loves you!
"人若赚得全世界,赔上自己的生命,有什么益处呢?人还能拿什么换生命呢? " 《圣经》( 马太福音 16:26 )
标签:
原文地址:http://www.cnblogs.com/gexd/p/5545256.html