如何於 CLP 中執行 SQL 指令 ? IBM 於 V6R1, V7R1 提供 PTF 安裝新 RUNSQL 的 command
IBM 終於提供於 CL 中執行 SQL 指令,RUNSQL,於此之前已有許多使用者自行開發的類似指令也稱為 RUNSQL(使用 google AS400 RUNSQL),
若你有安裝其他版本時,使用時要注意,是使用到哪一個版本,可使用 WRKOBJ OBJ(*ALL/RUNSQL) TYPE(*CMD) 
找出所有 RUNSQL,其中系統提供的是 QSYS/RUNSQL,若與你現有程式有衝突時,你可視需要決定要繼續使用原自有版本,還是使用系統提供的版本。
系統提供的 RUNSQL 可以接受參數 SQL 指令長度達到 5000,遠大於現有其他使用者自製的 RUNSQL 或 RUNSQLSTM 的 SQL 參數長度,所以建議使用系統提供的 RUNSQL。
V6R1 PTF SI46477 APAR SE51168:
http://www-912.ibm.com/n_dir/NAS4APAR.NSF/c79815e083182fec862564c00079d117/017071ddebbcb95f862579b200424d1f?OpenDocument
V7R1 PTF SI46219 APAR SE51276:
http://www-912.ibm.com/n_dir/NAS4APAR.NSF/c79815e083182fec862564c00079d117/cad15fd4018943b1862579ba00424874?OpenDocument
File  : QCLSRC
Member: RUNSQLTST
Type  : CLP
Usage : CRTCLPGM yourlib/RUNSQLTST
        CALL RUNSQLTST '800000'
        此範例是將 QIWS/QCUSTCDT 客戶編號大於 800000 客戶資料,排序複製到 QTEMP,並將之客戶編號輸出到螢幕。
OS    : V6R1以上
Pgm          (&SELECT)
     Dcl        &SELECT     *CHAR 6
     Dcl        &CUSNUMC    *CHAR 6
     Dcl        &SQLSTM     *CHAR 5000
     Dclf       QCUSTCDT
/*-- Global error monitoring:  --------------------------------------*/
     MonMsg     CPF0000     *N         GoTo Error
     ChgVar     &CUSNUMC    &SELECT
     ChgVar     &SqlStm     'drop table qtemp/cust'
     RunSql     Sql(&SqlStm) Commit(*None)
     MonMsg     SQL0204
     ChgVar     &SqlStm                                             +
                 (                                                  +
                  'Create table qtemp/cust as (' *CAT               +
                  'select * from qiws/qcustcdt where cusnum <' *CAT +
                  &cusnumc *BCAT                                    +
                  'order by cusnum' *cat                            +
                  ') with data'                                     +
                 )
     RunSql     Sql(&SqlStm) Commit(*None)
     OvrDbf     File(QCUSTCDT) ToFile(Qtemp/Cust) LvlChk(*NO)
Read:
     Rcvf
     MonMsg     CPF0864 *N GOTO EOF
     ChgVar     &CUSNUMC &CUSNUM
     SndPgmMsg  Msg('READ CUSNUM=' *CAT &CUSNUMC)
     Goto Read
Eof:
 Return:
     Return
/*-- Error processor ------------------------------------------------*/
Error:
     Call      QMHMOVPM    ( '    '                   +
                             '*DIAG'                  +
                             x'00000001'              +
                             '*PGMBDY   '             +
                             x'00000001'              +
                             x'0000000800000000'      +
                           )
     Call      QMHRSNEM    ( '    '                   +
                             x'0000000800000000'      +
                           )
 EndPgm:
     EndPgm
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期三, 11月 08, 2023
2012-05-22 如何於 CLP 中執行 SQL 指令 ? IBM new command RUNSQL from V6R1, V7R1
訂閱:
張貼留言 (Atom)
 
沒有留言:
張貼留言