informix dbaccess 常用執行方式及常見技巧


假設:

A.數據庫servername: testserver

B.數據庫名:testdb

C.SQL腳本文件:

   sqlfile.sql

   create table test_table(c1 integer);

   insert into test_table(c1) values(12);

   update test_table set c1=0;

   delete test_table where 1=1;

   drop table test_table;

   

   sqlfile2.sql

   create table test_table(c1 integer);

   insert into test_table(c2) values(12);

   insert into test_table(c1) values(12);

   update test_table set c1=0;

   delete test_table where 1=1;

   drop table test_table;

 

 


 

 

一.執行SQL腳本文件方式

 

1.調用dbaccess執行SQL腳本文件

  A.簡單執行SQL文件

     dbaccess testdb sqlfile.sql 或者  dbaccess testdb@testserver sqlfile.sql

     Database selected.
     Table created.
     1 row(s) inserted.
     1 row(s) updated.
     1 row(s) deleted.
     Table dropped.
     Database closed.

 

  B.執行輸出打印執行語句及執行結果

     dbaccess -e testdb sqlfile.sql

     create table test_table(c1 integer);
       Table created.
     insert into test_table(c1) values(12);
       1 row(s) inserted.
     update test_table set c1=0;
       1 row(s) updated.

     delete test_table where 1=1;
       1 row(s) deleted.

     drop table test_table;
       Table dropped.
     Database closed.

  C.將執行結果重定向到文件(shell: bash)

     dbaccess -e testdb sqlfile.sql > output.log > 2&1

     cat output.log

     create table test_table(c1 integer);
       Table created.
     insert into test_table(c1) values(12);
       1 row(s) inserted.
     update test_table set c1=0;
       1 row(s) updated.

     delete test_table where 1=1;
       1 row(s) deleted.

     drop table test_table;
       Table dropped.
     Database closed.

 

二.交互模式執行語句

    dbaccess - -
    > database testdb;

        Database selected.

     > create table test_table(c1 integer);
        Table created.

     > insert into test_table(c1) values(12);
        1 row(s) inserted.
     > update test_table set c1=0;
        1 row(s) updated.

     > delete test_table where 1=1;
        1 row(s) deleted.

     > drop table test_table;
        Table dropped.

     >^D

 

三.菜單模式執行

    進入數據庫

   dbaccess  選擇數據庫

   或者

    dbaccess testdb

    dbaccess testdb@testserver

   按菜單操作執行SQL語句,其中可以使用vi進行腳本文件的編輯

 

四.幾個小技巧

  1.執行SQL腳本文件時,當出錯時打印詳細的錯誤信息

    dbaccess -e -m testdb sqlfile2.sql

   

 Database selected.
 
create table test_table(c1 integer);
   Table created

 
insert into test_table(c2) values(1212);
  217: Column (c2) not found in any table in the query (or SLV is undefined).
Error in line 2
Near character position 26
 
   insert into test_table(c1) values(12);
1 row(s) inserted.
      update test_table set c1=0;
1 row(s) updated.
         delete test_table where 1=1;
1 row(s) deleted.
            drop table test_table;
Table dropped.
Database closed.

 

  2.執行SQL腳本文件時,當出錯時打印詳細的錯誤信息並在出現第一個錯誤時,停止繼續執行后續的語句

    dbaccess -e -m -a testdb sqlfile2.sql

    Database selected.
 
create table test_table(c1 integer);
Table created.
 
insert into test_table(c2) values(1212);
  217: Column (c2) not found in any table in the query (or SLV is undefined).
Error in line 2
Near character position 26
 
Database closed.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM