COBOL array data insert into Oracle

Oracle procob support multi-row insert into database.



-- WSS Definition --


EXEC SQL BEGIN DECLARE SECTION END-EXEC.

       01 ROWS-TO-INSERT PIC S9(4) COMP.


     *  DEFINE DATA ROW STRUCTURE

       01 TABLE-ROWS OCCURS 4 TIMES.

          03 S-SEQ-NUM     PIC S9(8) COMP-3 .

          03 S-NAME            PIC X(8)         .

          03 S-ID                    PIC S9(4) COMP-3 .

          03 SCORE-Y           PIC X(4)         .

     * DEFINE INDICATOR

       01 I-TABLE-ROWS OCCURS 4 TIMES.

          03 I-S-SEQ-NUM    PIC S9(4) COMP .

          03 I-S-NAME          PIC S9(4) COMP .

          03 I-S-ID                  PIC S9(4) COMP .

          03 I-SCORE-Y         PIC S9(4) COMP .


      * ANOTHER WAY TO DEFINE ROW STRUCTURE

      * OCCURS CAN BE DEFINED ON EITHER ROWS OR FIELDS

       01 TABLE-ROW.

          03 S-SEQ-NUM-S    PIC S9(8) COMP-3  OCCURS 4 TIMES.

          03 S-NAME-S          PIC X(8)                    OCCURS 4 TIMES     .

          03 S-ID-S                 PIC S9(4)  COMP-3  OCCURS 4 TIMES.

          03 SCORE-Y-S        PIC X(4)                    OCCURS 4 TIMES.


       01 I-TABLE-ROWS.

          03 I-S-SEQ-NUM-S   PIC S9(4) COMP OCCURS 4 TIMES.

          03 I-S-NAME-S         PIC S9(4) COMP OCCURS 4 TIMES.

          03 I-S-ID-S                PIC S9(4) COMP OCCURS 4 TIMES.

          03 I-SCORE-Y-S       PIC S9(4) COMP OCCURS 4 TIMES.


EXEC SQL END DECLARE SECTION END-EXEC.


-- INSERT: insert all 4 rows

EXEC SQL

   INSERT INTO V16TABLE VALUES (:TABLE-ROWS)

END-EXEC.


-- INSERT: insert 2 rows

MOVE 2 TO ROWS-TO-INSERT.

EXEC SQL

   FOR :ROWS-TO-INSERT

   INSERT INTO V16TABLE VALUES (:TABLE-ROWS)

END-EXEC.


-- INSERT: insert 2 rows with indicator

MOVE 2 TO ROWS-TO-INSERT.

EXEC SQL

   FOR :ROWS-TO-INSERT

   INSERT INTO V16TABLE VALUES (:TABLE-ROWS :I-TABLE-ROWS)

END-EXEC.


-- INSERT: insert 2 rows with column definition

MOVE 2 TO ROWS-TO-INSERT.

EXEC SQL

     FOR :ROWS-TO-INSERT

     INSERT INTO V16TABLE(S_SEQ_NUM, S_NAME, S_ID, SCORE_Y)

         VALUES (:TABLE-ROWS :I-TABLE-ROWS)

END-EXEC.


-- INSERT: insert 2 rows with occurs fields value

MOVE 2 TO ROWS-TO-INSERT.

EXEC SQL

    FOR :ROWS-TO-INSERT

    INSERT INTO V16TABLE(S_SEQ_NUM, S_NAME, S_ID, SCORE_Y)

        VALUES (:S-SEQ-NUM-S,

                         :S-NAME-S,

                         :S-ID-S,

                         :SCORE-Y-S)

END-EXEC.


or with indicator


MOVE 2 TO ROWS-TO-INSERT.

EXEC SQL

    FOR :ROWS-TO-INSERT

    INSERT INTO V16TABLE(S_SEQ_NUM, S_NAME, S_ID, SCORE_Y)

        VALUES (:S-SEQ-NUM-S:I-S-SEQ-NUM-S,

                         :S-NAME-S:I-S-NAME-S,

                         :S-ID-S:I-S-ID-S,

                         :SCORE-Y-S:I-SCORE-Y-S)

END-EXEC.


Notice:

FOR :ROWS-TO-INSERT INSERT ...

The FOR clause is handled by procob, it's not a valid SQL grammar, so this FOR clause cannot be used in dynamic SQL.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值