12、Load 操作
在進行load的時候
- db2 "load from acmmst.txt of del modifIEd by coldel| replace into acmmst nonrecoverable ”
由於數據不規范出現錯誤,強行中斷以後,進行操作的時候出現如下錯誤:
- SQL0668NOperation not allowed for reason code "3" on table "BTP.ACMMST".
- SQLSTATE=57016
此時,進行反方向操作即可:
- db2 "load from /dev/null of del terminate into acmmst nonrecoverable"。
如果沒有使用參數nonrecoverable,則會出現DB2數據庫狀態不正確的情況,使用:
db2 list tablesapces show detail 查看狀態,如果不是正常狀態,則脫機狀態進行備份即可。
兩個表文件之間UPDATE的方法:
- db2 "update cdmcrd set offset = (select cdmlsl.offset from cdmlsl where cdmlsl.crdno=cdmcrd.crdno) where cdmcrd.crdno in (select cdmlsl.crdno from cdmlsl)
13、多字段條件查詢和修改
表A中的字段有actno, cnlno,bal,pwd;表B中的字段為Actno,Cnlno,TxnAmt;目的是將A表中的bal修改為B表中的TxnAmt,命令:
- db2 "update A set bal=(select txnamt from B where actno=A.actno and cnlno=A.Cnlno) where A.actno||A.cnlno in (select Actno||cnlno from B );
14、多條件匹配查詢
查詢某個表中條件是B?AAA的記錄:
- db2 "select * from A where actno like 'B_AAA%'".
查詢數據中存在某些字符的記錄:
- db2 "select * from A where actno like '%-AAA%".
15、數據庫恢復的處理
進行DB2數據庫恢復的時候使用以下的命令:
以下是引用片段:
- restore db db1 to /tstdb2/catalog into db newlogpath /tstdb2/db2log buffer 2048
- replace existing redirect parallelism 16;
- set tablespace containers for 1 using (path '/tstdb2/db2tmp');
- set tablespace containers for 2 using
- (device '/dev/rtstcontlv00' 2621440, device '/dev/rtstcontlv01' 2621440,
- device '/dev/rtstcontlv02' 2621440, device '/dev/rtstcontlv03' 2621440 ) ;
- restore db db1 continue;
恢復完成以後執行命令db2s時報如下的錯誤:
以下是引用片段:
- P570:>db2s
- SQL1117N A connection to or activation of database "DB" cannot be made
- because of ROLL-FORWARD PENDING. SQLSTATE=57019
- DB21034E The command was processed as an SQL statement because it was not a
- valid Command Line Processor command. During SQL processing it returned:
- SQL1024N A database connection does not exist. SQLSTATE=08003
解決辦法如下:
以下是引用片段:
- P570:>db2 rollforward db db to end of logs and complete
- Rollforward Status
- Input database alias = db
- Number of nodes have returned status = 1
- Node number = 0
- Rollforward status = not pending
- Next log file to be read =
- Log files processed = -
- Last committed transaction = 2005-11-20-10.59.23.000000
- DB20000I The ROLLFORWARD command completed successfully.
以上的相關內容就是對DB2數據庫部分日常實用操作的介紹,望你能有所收獲。