以批处理方式执行多条SQL语句的测试过程和总结

发表于:2007-05-26来源:作者:点击数: 标签:
如何以批处理的方式执行多条SQL语句,本文将把整个 测试过程 作了详细介绍。 关于以批处理方式执行多条SQL语句的办法,测试过程如下: 1、建立QINGZHOU/QTXTSRC( MULTISQL),类型为TXT。 Columns . . . : 1 71 Browse QINGZHOU/QTXTSRC SEU== MULTISQL FMT *

如何以批处理的方式执行多条SQL语句,本文将把整个测试过程作了详细介绍。

关于以批处理方式执行多条SQL语句的办法,测试过程如下:

1、建立QINGZHOU/QTXTSRC( MULTISQL),类型为TXT。

Columns . . . :    1  71           Browse                     QINGZHOU/QTXTSRC
 SEU==>                                                                MULTISQL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0001.00                                                                        
0002.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV005';        
0003.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV006';        
0004.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV007';        
0005.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV008';        
0006.00                                                                        
        ****************** End of data ****************************************
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
 F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle   F12=Cancel     
 F16=Repeat find        F24=More keys                                          
                                         (C) COPYRIGHT IBM CORP. 1981, 2002.
   

2、更新前通过STRSQL检查QINGZHOU/INVOICE这个PF的数据如下:
===>SELECT * FROM QINGZHOU/INVOICE

                                         Display Data    

                              
                                              Data width . . . . . . :      87 
 Position to line  . . . . .              Shift to column  . . . . . .         
 ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....
  发票    名称              总数                 总金额    备注                
 IV001    TT机             100              10,000.00  RICOH 速印机系列     
 IV002    PG机              30              60,000.00  RICOH 速印机系列     
 IV003    HQPG机           10              20,000.00  RICOH 速印机系列     
 IV004    UNIT机          200              10,000.00  RICOH 速印机系列     
 IV005    INKI          1,000              10,000.00  RICOH 耗材系列       
 IV006    MAST          1,000              40,000.00  RICOH 耗材系列       
 IV007    FAX            5,000             150,000.00  RICOH 传真机系列     
 IV008    PRINT       30,000           1,500,000.00  RICOH 打印机系列     
 IV009    黑色激打           500              50,000.00  RICOH 激光打印机系列 
 IV010    彩色激打         90,000          18,000,000.00  RICOH 激光打印机系列 
 IV011   RICOH 复印           200             120,000.00  RICOH 复印机系列     
 IV012   RICOH 数码        80,000          24,000,000.00  RICOH 数码相机系列   
 IV013   RICOH 芯片           600          60,000,000.00  RICOH 存储系列       
 ********  End of data  ********                                               
                                                                               
                                                                               
                                                                       Bottom  
 F3=Exit      F12=Cancel      F19=Left      F20=Right      F21=Split 

3、OS/400命令行执行:
===>RUNSQLSTM SRCFILE(QINGZHOU/QTXTSRC) SRCMBR(MULTISQL) COMMIT(*NONE)
☆特别提醒:
如果不是使用事务处理,应该将COMMIT(*CHG)→COMMIT(*NONE),否则执行RUNSQLSTM命令出错,而且会造成SQL语句失效。

4、再次执行===>SELECT * FROM QINGZHOU/INVOICE检查数据,发现数据已经得到批量更新:

Display Data                                 
                                              Data width . . . . . . :      87 
 Position to line  . . . . .              Shift to column  . . . . . .         
 ....+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....
  发票    名称              总数                 总金额    备注                
 IV001    TT机             100              10,000.00  RICOH 速印机系列     
 IV002    PG机              30              60,000.00  RICOH 速印机系列      
 IV003    HQPG机           10              20,000.00  RICOH 速印机系列     
 IV004    UNIT机          200              10,000.00  RICOH 速印机系列     
 IV005   QINGZHOU           1,000              10,000.00  RICOH 耗材系列       
 IV006   QINGZHOU           1,000              40,000.00  RICOH 耗材系列       
 IV007   QINGZHOU           5,000             150,000.00  RICOH 传真机系列     
 IV008   QINGZHOU          30,000           1,500,000.00  RICOH 打印机系列     
 IV009    黑色激打           500              50,000.00  RICOH 激光打印机系列 
 IV010    彩色激打         90,000          18,000,000.00  RICOH 激光打印机系列 
 IV011   RICOH 复印           200             120,000.00  RICOH 复印机系列     
 IV012   RICOH 数码        80,000          24,000,000.00  RICOH 数码相机系列   
 IV013   RICOH 芯片           600          60,000,000.00  RICOH 存储系列       
 ********  End of data  ********                                               
                                                                               
                                                                               
                                                                       Bottom  
 F3=Exit      F12=Cancel      F19=Left      F20=Right      F21=Split     


5、修改MULTISQL中SQL语句,追加SELECT语句,再次执行:RUNSQLSTM SRCFILE(QINGZHOU/QTXTSRC) SRCMBR(MULTISQL) COMMIT(*NONE) ,结果系统提示错误: RUNSQLSTM command failed.

 Columns . . . :    1  71           Browse                     QINGZHOU/QTXTSRC
 SEU==>                                                                MULTISQL
 FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
        *************** Beginning of data *************************************
0001.00 SELECT * FROM INVOICE;                                                 
0002.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV005';        
0003.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV006';        
0004.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV007';        
0005.00 UPDATE INVOICE SET  IV_NAME = 'QINGZHOU' WHERE IV_CODE='IV008';        
0006.00                                                                        
        ****************** End of data ****************************************
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
 F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle   F12=Cancel     
 F16=Repeat find        F24=More keys                                          
                                         (C) COPYRIGHT IBM CORP. 1981, 2002


6、总结:

(1). SQL语句的成员类型一定要指定为TXT;
(2). 每条语句要以分号“;”结束;
(3). 不支持Select语句;
(4). 如果不是使用事务处理,应该将COMMIT(*CHG)—>COMMIT(*NONE),否则执行RUNSQLSTM命令出错,而且会造成SQL语句失效。

原文转自:http://www.ltesting.net