In this post, I will show you how to write an SQL query that inserts an 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.
“no matter who you are, no matter what you do, no matter who your audience is: 30 percent will love it, 30 percent will hate it, and 30 percent won’t care. Stick with the people who love you and don’t spend a single second on the rest. Life will be better that way.”
― James Altucher, Choose Yourself
As usual, in INSERT SQL you need to supply values as Host-Variables.
SQL Query to Insert Array of Values into DB2 Table
EXEC SQL INSERT INTO srinmf_test (ACT_NO, ACT_KWD, ACT_DESC) VALUES (:HV1, :HV2, :HV3) FOR :NUM-ROWS ROWS END-EXEC.
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