COBOL array data insert into Oracle

2019-04-15 19:18发布

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.