How to INSERT Array of Values into DB2 Table

Here is an SQL query that to INSERT array of values into a DB2 table.

In DB2 or any RDBMS, there are a variety of rules you need to follow before inserts a row into a Table. In my previous post DB2: 4 TOP QUESTIONS ON SQL INSERT VALUES, I have explained these.

Here is Apache Spark3 With Scala Hands-on

SQL Query to Insert Array of Values into DB2 Table

Below is INSERT SQL. Here you need to supply Array of VALUES.

EXEC SQL
  INSERT INTO srinmf_test 
    (ACT_NO, ACT_KWD, ACT_DESC)
    VALUES (:HV1, :HV2, :HV3)
    FOR :NUM-ROWS ROWS
END-EXEC.

Explanation:

  • In the above query, the table name is srinimf_test.
  • The ACT_NO, ACT_KWD, ACT_DESC are the column names in that table.
:HV1, :HV2 and :HV3 are host variables.
  • The num_rows in For clause says, the number of rows to insert.
  • This way of writing SQL Query is called array inserting in DB2.

Related Posts

Get new content delivered directly to your inbox.

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading