by 김대현이 [SQL Query] forall sqlrowcount [2017.03.17 15:00:57]
declare type col_1_at is table of varchar2(50) index by pls_integer; type col_2_at is table of varchar2(50) index by pls_integer; type col_3_at is table of number index by pls_integer; l_col_1 col_1_at := :col_1s; --Array bind value l_col_2 col_2_at := :col_2s; --Array bind value l_col_3 col_3_at := :col_3s; --Array bind value begin forall i in l_col_1.first .. l_col_1.last insert /*+ ignore_row_on_dupkey_index(table_name, table_name_PK) */ into table_name(col_1, col_2, col_3) values (to_date(l_col_1 (i), 'yyyymmddhh24miss'), l_col_2 (i), l_col_3 (i)); end;
위와 같이 익명 pl/sql문을 사용 하고, insert할때 힌트를 줘서 중복되는 행은 insert 되는 걸 막고 있습니다.
여기서 궁금 한점은 만약 array value를 10건 insert 했을 때, 중복되는 행을 제외 하고 몇 행이 insert됐는가를 return 받고 싶은데
방법을 모르겠어요 node-oracledb를 사용 중인데 :col_1s 는 IN_BIND 변수 이고,
변수를 하나 더 만들어 몇개의 행이 insert 되었는지 OUT_BIND 변수로 받고 싶어요..
SQL%ROWCOUNT 를 이용해 보세요.
http://www.gurubee.net/lecture/1062