简体   繁体   中英

DB2 LUW 9.X: Multirow insert in stored procedures

what is the best way performancewise to insert multiple rows to a table from a stored procedure?

EXEC SQL
  INSERT INTO DSN8A10.ACT 
    (ACTNO, ACTKWD, ACTDESC)
    VALUES (:HVA1, :HVA2, :HVA3)
    FOR :NUM-ROWS ROWS
END-EXEC.

The above is apparently only available in z/os but not in luw. Is there any equivalent?

"DB2 9.x" is a bit too broad of a specification. Beginning with DB2 9.7 you might use the UNNEST() table function , something like this:

insert into ACT (ACTNO, ACTKWD, ACTDESC) 
select ACTNO, ACTKWD, ACTDESC from unnest (V_ARR) as (ACTNO, ACTKWD, ACTDESC);

assuming V_ARR is an array of row type with "columns" ACTNO , ACTKWD , and ACTDESC .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM